• HI,

    I have been trying to separate the categories displayed on a site that I am working on, so that when you enter into a single post, the below navigation only displays the next post from that category instead of the next post that was published from the main loop.

    I have tried category separating plugins and variations of <?php query_posts($query_string . ‘&cat=-9’); ?> and they work for the main cageory page, but once you enter a post for more information the links below still take you to the next post in the main loop.

    Any help would be greatly appreciated!!

Viewing 7 replies - 1 through 7 (of 7 total)
  • To get the whole post as an object –

    <?php $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous) ?>

    or for just the link –

    <?php
    previous_post_link($format, $link, $in_same_cat = false, $excluded_categories = '');
    next_post_link($format, $link, $in_same_cat = false, $excluded_categories = '');
    ?>
    Thread Starter angusfoggo

    (@angusfoggo)

    Thanks for the quick response, would this be used to replace the php for the below post navigation?

    Thread Starter angusfoggo

    (@angusfoggo)

    Also would it interfere with the below navigation of loop-single if you access it from the main site loop?

    It really depends on exactly what you want, so I can’t say as I have no idea what your code look like, but you can use just some of that code to produce navigation links.

    Below is exactly what I have on my site to produce ‘Next post’ and ‘Previous post’ links –

    <div id="post-navigation-links">
    	<div class="nav-previous floatLeft"><p><?php previous_post_link('%link', '&laquo; Previous Post', false); ?></p></div>
    	<div class="nav-next floatRight"><p><?php next_post_link('%link', 'Next Post &raquo;', false); ?></p></div>
    	<div class="clearMe"></div>
    </div>

    And I’m afraid I’m not sure what you mean by the second question, but the code above must be used in the loop – i.e. in your single.php template, after –

    <?php if(have_posts()) : while(have_posts()) : the_post(); ?>

    I’d recommend searching them in Google and having a good read of the of the documentation on the WP website.

    Thread Starter angusfoggo

    (@angusfoggo)

    Sorry about the confusion, the main reason I have found it difficult to research exactly what I am looking for is that I am finding it hard to articulate the problem.

    I currently have a ‘loop-category.php’ file that I want to display posts from only the ‘news’ category (category 9 on the site), i have used <?php query_posts($query_string . ‘&cat=9’); ?> above <?php while ( have_posts() ) : the_post(); ?> so the category page only displays posts from the specified category, which works. But when you click on the post to view all of the information the navigation below the post (in loop-single.php) links you to posts that are outside of the category.

    Thread Starter angusfoggo

    (@angusfoggo)

    Thanks again for your help so far duck boy

    So ‘loop-category.php’ is an index (a list of posts)?

    Ok, I get you – you can use the code I suggested for this purpost as one of the params is $in_same_cat. Set that to true, and your navigation will only show the next/previous post from that category.

    If you don’t want that for the rest of your single posts, then maybe set up an almost copy of ‘loop-single.php’ (say ‘loop-single-category.php’), wiht just the navigation different.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Category loop’ is closed to new replies.