Discussion:
Posts 2 Posts: Pagination for connected posts on single post template
Md Mahmudur Rahman
2013-06-27 09:07:30 UTC
Permalink
Hello Hackers,

I'm using Posts 2
Posts<http://wordpress.org/extend/plugins/posts-to-posts/description/>
plugin
to create connection for artists and posts. This way the site can display
the artist details and connected posts (news/photo galleries/videos) about
the artist on a single page.

I modified the single-artist.php to show the artist details (primary loop)
and connected posts (secondary loop) below it. I can get the connected post
and paginate them by the following code but the pagination links are not
working.

// Find connected posts
$connected = new WP_Query( array(
'connected_type' => 'artists_to_posts',
'connected_items' => get_queried_object(),
'paged' => (get_query_var('page')) ? get_query_var('page') : 1,
) );

As a result, when I am going to
http://localhost/artist/artist-name/page/2 redirects
me back to http://localhost/artist/artist-name/ so I can't go to the
paginated links and can only see the most recent connected posts.

Here is:

*single-artist.php<https://gist.github.com/iammahmudur/19d944872cfac1c285cf>
*

I know the single post template is only meant to show the current post, so
I'm not sure what should I do in this case. Hope someone can give me a
clue.
--
*Many thanks*
*
*
*Mahmudur Rahman*
J.D. Grimes
2013-06-27 13:38:08 UTC
Permalink
Have you tried get_query_var( 'paged' ) instead?

- J.D. Grimes
Post by Md Mahmudur Rahman
Hello Hackers,
I'm using Posts 2
Posts<http://wordpress.org/extend/plugins/posts-to-posts/description/>
plugin
to create connection for artists and posts. This way the site can display
the artist details and connected posts (news/photo galleries/videos) about
the artist on a single page.
I modified the single-artist.php to show the artist details (primary loop)
and connected posts (secondary loop) below it. I can get the connected post
and paginate them by the following code but the pagination links are not
working.
// Find connected posts
$connected = new WP_Query( array(
'connected_type' => 'artists_to_posts',
'connected_items' => get_queried_object(),
'paged' => (get_query_var('page')) ? get_query_var('page') : 1,
) );
As a result, when I am going to
http://localhost/artist/artist-name/page/2 redirects
me back to http://localhost/artist/artist-name/ so I can't go to the
paginated links and can only see the most recent connected posts.
*single-artist.php<https://gist.github.com/iammahmudur/19d944872cfac1c285cf>
*
I know the single post template is only meant to show the current post, so
I'm not sure what should I do in this case. Hope someone can give me a
clue.
--
*Many thanks*
*
*
*Mahmudur Rahman*
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Md Mahmudur Rahman
2013-06-27 23:37:34 UTC
Permalink
Hi

I have tried that as well. But no luck.

The pagination links are part of a secondary loop on a single page
template. And I can see that get_query_var('paged') always returning 1. As
a result the pagination links are not working.

Is it possible to paginate through a secondary loop on a *single page
template*? For example, on a single page template can I have a URL like
below:

http://localhost/artist/artist-name/page/2

Here is the link for:

single-artist.php <https://gist.github.com/iammahmudur/19d944872cfac1c285cf>
loop-artist.php <https://gist.github.com/iammahmudur/8f38979f143cdc668ff9>

Pagination code on functions.php<https://gist.github.com/iammahmudur/5881276>

Many thanks.
Post by J.D. Grimes
Have you tried get_query_var( 'paged' ) instead?
- J.D. Grimes
Post by Md Mahmudur Rahman
Hello Hackers,
I'm using Posts 2
Posts<http://wordpress.org/extend/plugins/posts-to-posts/description/>
plugin
to create connection for artists and posts. This way the site can display
the artist details and connected posts (news/photo galleries/videos)
about
Post by Md Mahmudur Rahman
the artist on a single page.
I modified the single-artist.php to show the artist details (primary
loop)
Post by Md Mahmudur Rahman
and connected posts (secondary loop) below it. I can get the connected
post
Post by Md Mahmudur Rahman
and paginate them by the following code but the pagination links are not
working.
// Find connected posts
$connected = new WP_Query( array(
'connected_type' => 'artists_to_posts',
'connected_items' => get_queried_object(),
'paged' => (get_query_var('page')) ? get_query_var('page') : 1,
) );
As a result, when I am going to
http://localhost/artist/artist-name/page/2 redirects
me back to http://localhost/artist/artist-name/ so I can't go to the
paginated links and can only see the most recent connected posts.
*single-artist.php<
https://gist.github.com/iammahmudur/19d944872cfac1c285cf>
Post by Md Mahmudur Rahman
*
I know the single post template is only meant to show the current post,
so
Post by Md Mahmudur Rahman
I'm not sure what should I do in this case. Hope someone can give me a
clue.
--
*Many thanks*
*
*
*Mahmudur Rahman*
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
*Many thanks*
*
*
*Md Mahmudur Rahman*
J.D. Grimes
2013-06-27 23:57:33 UTC
Permalink
Does it work if you add the page number as a GET parameter?

For Example, http://localhost/artist/artist-name/?page=2

-J.D. Grimes
Post by Md Mahmudur Rahman
Hi
I have tried that as well. But no luck.
The pagination links are part of a secondary loop on a single page
template. And I can see that get_query_var('paged') always returning 1. As
a result the pagination links are not working.
Is it possible to paginate through a secondary loop on a *single page
template*? For example, on a single page template can I have a URL like
http://localhost/artist/artist-name/page/2
single-artist.php <https://gist.github.com/iammahmudur/19d944872cfac1c285cf>
loop-artist.php <https://gist.github.com/iammahmudur/8f38979f143cdc668ff9>
Pagination code on functions.php<https://gist.github.com/iammahmudur/5881276>
Many thanks.
Md Mahmudur Rahman
2013-06-28 00:24:08 UTC
Permalink
Hi

If I set the page number as a GET parameter then it works for the first
loop/primary loop and not for the secondary loop. As a result the URL
becomes:

http://localhost/artist/artist-name/2/<http://localhost/artist/artist-name/?page=2>

Here is the response (WP_Query Object) for the first loop:

https://gist.github.com/iammahmudur/88beda1b000acd806144

And here is the response (WP_Query Object) for the second loop:

https://gist.github.com/iammahmudur/2b526713a14fb3b8fd05

How can I set the 'page' parameter for the second loop?

Many thanks.
Post by J.D. Grimes
Does it work if you add the page number as a GET parameter?
For Example, http://localhost/artist/artist-name/?page=2
-J.D. Grimes
Post by Md Mahmudur Rahman
Hi
I have tried that as well. But no luck.
The pagination links are part of a secondary loop on a single page
template. And I can see that get_query_var('paged') always returning 1.
As
Post by Md Mahmudur Rahman
a result the pagination links are not working.
Is it possible to paginate through a secondary loop on a *single page
template*? For example, on a single page template can I have a URL like
http://localhost/artist/artist-name/page/2
single-artist.php <
https://gist.github.com/iammahmudur/19d944872cfac1c285cf>
Post by Md Mahmudur Rahman
loop-artist.php <
https://gist.github.com/iammahmudur/8f38979f143cdc668ff9>
Post by Md Mahmudur Rahman
Pagination code on functions.php<
https://gist.github.com/iammahmudur/5881276>
Post by Md Mahmudur Rahman
Many thanks.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
*Many thanks*
*
*
*Md Mahmudur Rahman*
Md Mahmudur Rahman
2013-06-28 00:36:43 UTC
Permalink
Hi,

This is now working. I have changed the arguments for my second query as
given below:

// Find connected posts
$connected = new WP_Query( array(
'connected_type' => 'artists_to_posts',
'connected_items' => get_queried_object(),
'paged' => (get_query_var('page')) ? get_query_var('page') : 1,
) );

Thanks for your help.

Cheers.

Mahmudur

On Fri, Jun 28, 2013 at 10:24 AM, Md Mahmudur Rahman
Post by Md Mahmudur Rahman
Hi
If I set the page number as a GET parameter then it works for the first
loop/primary loop and not for the secondary loop. As a result the URL
http://localhost/artist/artist-name/2/<http://localhost/artist/artist-name/?page=2>
https://gist.github.com/iammahmudur/88beda1b000acd806144
https://gist.github.com/iammahmudur/2b526713a14fb3b8fd05
How can I set the 'page' parameter for the second loop?
Many thanks.
Post by J.D. Grimes
Does it work if you add the page number as a GET parameter?
For Example, http://localhost/artist/artist-name/?page=2
-J.D. Grimes
Post by Md Mahmudur Rahman
Hi
I have tried that as well. But no luck.
The pagination links are part of a secondary loop on a single page
template. And I can see that get_query_var('paged') always returning 1.
As
Post by Md Mahmudur Rahman
a result the pagination links are not working.
Is it possible to paginate through a secondary loop on a *single page
template*? For example, on a single page template can I have a URL like
http://localhost/artist/artist-name/page/2
single-artist.php <
https://gist.github.com/iammahmudur/19d944872cfac1c285cf>
Post by Md Mahmudur Rahman
loop-artist.php <
https://gist.github.com/iammahmudur/8f38979f143cdc668ff9>
Post by Md Mahmudur Rahman
Pagination code on functions.php<
https://gist.github.com/iammahmudur/5881276>
Post by Md Mahmudur Rahman
Many thanks.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
*Many thanks*
*
*
*Md Mahmudur Rahman*
--
*Many thanks*
*
*
*Md Mahmudur Rahman*
Loading...