Skip Navigation

[Resolved] How do I add a link to the next post within the same category?

This support ticket is created 7 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by joshM-4 7 years, 5 months ago.

Assisted by: Minesh.

Author
Posts
#450366

I am trying to: add a link to the next post within the same category in a content template

I visited this URL: hidden link

Example: a visitor is reading a "Deal Story" (custom post type) in the category of "Consulting" (custom taxonomy). I would like to add a link within the content template here that takes the reader to the next Deal Story within that category. And if the Deal Story were in another category, the link should be for the next Deal Story within that category.

I'm sure it's simple, I just haven't been able to figure it out.

I really appreciate your help in advance.

#450539

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I reviewed the post URL you shared with me and I can see that it's single post page where you would like to add pagination links. Basically, single post pagination should be provided by the theme.

View's will allow you to create a LIST of your Posts and then, you can paginate that list.

But you can not paginate from one single Post to the next with a single CPT page. This needs to be provided by the Theme.

If your theme does not provide this, you could use Custom Code to create Pagination links.
This is described here:
https://codex.wordpress.org/Pagination
https://codex.wordpress.org/Next_and_Previous_Links

See example on the following link - this is not exactly you may need but you may get idea:
=> https://toolset.com/forums/topic/nextprevious-page-pagination-on-content-template-for-cpt/#post-261191

#450687

Thank you, Minesh. Those links were very helpful. I was able to insert the previous and next link area into the Deal Stories template with the following function from the example you shared:

function prefix_navigation_links() {
    if ( is_singular('deal-story') ) {
    ?>
        <span class="nav-previous alignleft"><?php previous_post_link('%link', 'Previous Post', TRUE) ?></span>
        <span class="nav-next alignright"><?php next_post_link('%link', 'Next Post', TRUE) ?></span>
       <?php
    }
}
add_action('x_after_the_content_end', 'prefix_navigation_links' );

But for some reason, the links themselves aren't showing up, just the span wrappers (which you can view when inspecting this page: hidden link )

Do you have any idea why those links wouldn't be showing up? Does it have to do with the custom post types or is it something else?

Thanks again for your help!

#450825

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please try following code. I've added 'echo' to your pagination links so that it will output the links.

function prefix_navigation_links() {
    if ( is_singular('deal-story') ) {
    ?>
        <span class="nav-previous alignleft"><?php 
echo previous_post_link('%link', 'Previous Post', TRUE); ?></span>
        <span class="nav-next alignright"><?php 
echo next_post_link('%link', 'Next Post', TRUE); ?></span>
       <?php
    }
}
add_action('x_after_the_content_end', 'prefix_navigation_links' );

I hope this solution will help you to resolve your issue.

#451002

Thank you for the additional assistance, Minesh. Unfortunately it still isn't working for me, but I don't think this is a Toolset issue anymore so I don't want to take up more of your time on basic WordPress and PHP.

I'll keep working on it, but we can go ahead and close this thread. Thanks again.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.