• I have templated WordPress site displaying products in different categories. I’d like to insert a “previous post in category” and “next post in category” link into the posts itself. The links need to be in the posts because of the current page layout and it wouldn’t work to have the links in the page template. Is this possible? How would I get started doing this? Can I use $wpdb or posts_nav_link or new WP_Query() in the posts itself?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi, davedev.
    Try to add this code in content-single.php inside content loop.

    `<?php previous_post_link( $format, $link, $in_same_term = false, $excluded_terms = ”, $taxonomy = ‘category’ ); ?>
    <?php next_post_link( $format, $link, $in_same_term = false, $excluded_terms = ”, $taxonomy = ‘category’ ); ?>

    <?php previous_post_link(‘%link’, ‘Previous post in category’, TRUE); ?> <?php echo “|”;?> <?php next_post_link(‘%link’, ‘Next post in category’, TRUE); ?>

    Thanks,

    Hanafi, Cyberjaya,

    Thread Starter davedev

    (@davedev)

    Thanks for the response. If I place the links in content-single.php wouldn’t the have to be above or below the posts content? My content is complex product descriptions with text, graphics, images, etc. and I want to do something like this:

    some post content
    next/prev links
    more post content

    Can the php and functions work in the body of the posts? Your response is helpful though if I have to go in that direction. Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Previous and Next Post Links Within a Posts’ is closed to new replies.