WordPress.org

Ready to get started?Download WordPress

Forums

Multiple categories & next_post_link (13 posts)

  1. heriz
    Member
    Posted 5 years ago #

    Hello all.

    Still having a big problem sorting out this conundrum.

    I'm developing my site (http://www.lewisheriz.com) locally using MAMP. Currently I'm adding posts to the subcategory Personal under the main category Work.

    If you navigate to the Client section under Work, you can see how the browsing system works: pieces under Client are listed down the side, and there's a prev/next section in the top right to scroll through them.

    The problem I'm having is that as soon as I include posts under the second subcategory Personal, the next/prev link reads them too, positioning them chronologically. This means that the browsing logic is broken; it takes you to the Personal section, changing the sidebar contents and confusing the system.

    Is there a way round this? Either as an edit to the 'next_post_link'/'prev_post_link' functions, or using a different hierarchical system?

    Ideally, I need a way of forcing next_post_link to read only posts in the subcategory. But after extensive searches (and asking on here) there seems to be no solution to this.

    I'm flummoxed.

    It is made even more of a problem when posts include extra categories - I'm putting each piece into a 'Posters' or 'Music Products' etc category, with a view to providing other ways of searching/browsing work. This may also confuse the system.

    Moshu - I noticed you have something similar on your site? Did you change the code/use a plugin, or is it really my set-up that's the problem?

    On top of this, browser caches and database updates seem to make the issue even harder to test - FF and Opera display the information differently depending on whether I'm logged in or not, for instance. It's a bit of a nightmare

    ANY help regarding any of this massively appreciated, as always.

  2. heriz
    Member
    Posted 5 years ago #

    Right, after testing I've found that it is purely having multiple categories that's the problem.

    That means that the exclude_categories in next_post_link doesn't seem to be working.

    Just to make sure, here's what I have:

    <div class="next-link"><?php previous_post_link('%link', '&nbsp;', TRUE, '213'); ?></div>
    <div class="prev-link"><?php next_post_link('%link', '&nbsp;', TRUE, '213'); ?></div>

    Where 213 is the parent of the 'Poster' category ('Sort' - the category I will use to sort all the post types).

    Anyway I'll press on. I may have to try and use tags instead.

  3. moshu
    Member
    Posted 5 years ago #

    next_post_link

    That is to be used on the single.php - when browsing from one individual post to another... NOT on the multipost view templates!

    And I don't see the "Personal" cat.

  4. heriz
    Member
    Posted 5 years ago #

    Hi Moshu. Sorry, I don't think I've been quite clear enough.

    This is on the single.php.

    The WORK category currently has two subcategories: CLIENT and PERSONAL. You won't see anything under PERSONAL yet because I'm testing this using localhost. Luckily.

    I have another category: SORT. Under this will be the types of work, such as POSTERS or MUSIC PRODUCTS. This is separate from WORK, so I can create a SORT page (with small p) that collects these SORT sub-categories together.

    Each post I put under either CLIENT or PERSONAL. But I will also put under the SORT type.

    The problem is this:

    When there are two posts in the same SORT sub-category, then the next_post_link in single.php includes that sub-category, even when the posts are in different WORK subcategories. This means that when browsing through each single view, it flicks between CLIENT and PERSONAL categories, favouring the SORT categories EVEN IF they are excluded, as shown above.

    I know this is quite confusing - do you see my problem? (Other than my intelligence.)

  5. moshu
    Member
    Posted 5 years ago #

    OK. single.php issue sorted.

    RE: categories... I am really confused sorry.

  6. heriz
    Member
    Posted 5 years ago #

    Not surprised. I'm going to keep trying with this. It's hard to explain.

    So you go to the Client section, and click on an item. This takes you to the single.php. You then start browsing through the client items using the forward or backward arrow (next/prev_post_link).

    This should do nothing more than take you - chronologically - through the Client work list in the sidebar.

    But if you land on a piece which is a Poster (in the Sort - Poster category), and chronologically in the database the next post is also in the Poster category (but in the PERSONAL category, NOT CLIENT), it will take you to the single view of that Poster work in the PERSONAL section.

    This means that the sidebar list changes to the Personal Work list, and the browsing logic is broken.

    I want to be able to have both Client and Personal work in the same SORT category. But because of this next_post_link problem, I can't.

    Is this any clearer?

  7. moshu
    Member
    Posted 5 years ago #

    This should do nothing more than take you - chronologically - through the Client work list in the sidebar.
    Not exactly. It should go (if coded properly) through the posts in THAT category. No matter what is in the sidebar. That's just another confusing element. And, btw, if you have a Loop in the sidebar to list them... that could also interfere with the working of the main Loop. It happens too often when users don't know how to work with multiple loops.

    I might not have this kind of "cross-linked" posts in non-related categories... but on my blog the template tags work exactly as I needed: on the top of any single post you can navigate in the category, while at the bottom you can go chronologically.

  8. heriz
    Member
    Posted 5 years ago #

    Sorry yes - it should take it through the posts in that category. But as the sidebar is just a list of the posts in that category, then it should give the impression of going through them in order.

    This is the issue. It does do this, but it also takes into account posts in other categories, even when they're excluded. This is what I don't understand.

    So with your next_post links, was the only difference that you kept out 'TRUE' in the parameters for the bottom link?

    I guess that this has at least located the problem, that it is definitely these 'cross-linked' posts that make my system unusable.

  9. heriz
    Member
    Posted 5 years ago #

    Oh and the sidebar loop is this code:

    <?php
    
    	$IDOutsideLoop = $post->ID;
    	global $post;
    
    	 $myposts = get_posts('showposts=100&category=175');
    	 foreach($myposts as $post) :
    	 ?>
    		<li<?php if(is_single() && $IDOutsideLoop == $post->ID) print ' class="current-post-item"'?>><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    
    <?php endforeach; ?>

    Whether this is interfering, I don't know.

  10. moshu
    Member
    Posted 5 years ago #

    Bottom:
    <?php previous_post_link('%link','%title', FALSE,'20'); ?>

    Top:
    <?php previous_post_link('%link', 'Previous post in same section', TRUE, '20'); ?>

    (my cat=20 is Asides, which I didn't want to include anywhere)

    What happens if you remove (temporarily) that loop from the sidebar?

  11. heriz
    Member
    Posted 5 years ago #

    Removing the sidebar Loop doesn't change anything.

    If I remove the 'Poster' category from the Personal post, then it all works fine. It is simply this cross-linking that's the problem.

    Thanks for your time Moshu, I think I'll try using tags - if this doesn't work, I'll give up. It's taking up too much time!

  12. swimy
    Member
    Posted 5 years ago #

    bump. did anyone get anywhere with this? it seems like a large problem.

  13. heriz
    Member
    Posted 4 years ago #

    Swimy, I gave up - I agree with Moshu, it's unnecessarily confusing. Using a next page function with multiple categories is bound to cause confusion.

    I used tags instead, which works fine.

Topic Closed

This topic has been closed to new replies.

About this Topic