WordPress.org

Ready to get started?Download WordPress

Forums

Ambrosite Next/Previous Post Link Plus
Using in_cats and ex_cats_method together? (4 posts)

  1. anielsen
    Member
    Posted 2 years ago #

    Here is my setup:

    • Site with lots of Posts
    • Each Post is a member of multiple Categories (I'll call them Cat1, Cat2, Cat3, etc)
    • I want the Next/Previous to cycle through all Posts in Cat1 (regardless of what other Categories it is in) and then echo "This is the last Post in this Section" when it reaches the last Post in Cat1.
    • But I then want it to do the same thing for all the Posts in Cat2 (regardless of what other Categories it is in), and for Cat3 and so on

    I was doing this in v.2.3 of this plugin by setting in_same_cat to true, setting the ex_cats_method to diff and then listing all the Categories I wanted it to ignore in ex_cats.

    With v.2.4 and the introduction of in_cats I thought this would make my life easier. I would just list the Categories I wanted it to key on instead of listing all the Categories to exclude (a much longer list). But when using in_cats, the ex_cats_method seems to be ignored. So when I get to the last post in Cat1 it goes right on to Cat2 instead of echoing my "This is the last Post in this Section" line.

    Am I just thinking of this fundamentally wrong (trying to use in_cats and ex_cats_method at the same time) or is it possible and I've just coded it wrong?

    TIA!

    http://wordpress.org/extend/plugins/ambrosite-nextprevious-post-link-plus/

  2. ambrosite
    Member
    Plugin Author

    Posted 2 years ago #

    The ex_cats_method has no effect whatsoever on in_cats. It applies only to ex_cats.

    If you are using in_cats, then you should not be using ex_cats, ex_cats_method, or in_same_cat (in fact, in_same_cat is disabled when in_cats is used).

    In regard to your specific problem, if you give me your code -- both the old way (using in_same_cat) and the new way (using in_cats) -- I may be able to advise you further.

  3. anielsen
    Member
    Posted 2 years ago #

    This code works, but requires I add every Category ID that I want to exclude as we add more Categories:

    <div id="next-previous-nav">
    	<?php if (previous_post_link_plus( array(
                             'order_by' => 'post_date',
                             'loop' => false,
    			 'link' => "Previous",
                             'tooltip' => 'Previous letter',
                             'in_same_cat' => true,
                             'ex_cats_method' => 'diff',
    			 'ex_cats' => '35493, 27136, 35316, 596, 455, 42965, 42968, 35502, 35504, 35500, 476, 1, 42963, 293',
                        ) ) );
    			else
    			echo "<em>This is the first page in this section</em>";
    			?> |
    	<?php if (next_post_link_plus( array(
                             'order_by' => 'post_date',
                             'loop' => false,
    			 'link' => "Next",
                             'tooltip' => 'Next letter',
                             'in_same_cat' => true,
                             'ex_cats_method' => 'diff',
    			 'ex_cats' => '35493, 27136, 35316, 596, 455, 42965, 42968, 35502, 35504, 35500, 476, 1, 42963, 293',
                        ) ) );
    			else
    			echo "<em>This is the last letter in the section</em>";
    			?>
    	</div>

    This code doesn't differentiate between when Category 35505 ends and 42971 begins, the Next>> just keeps on going:

    <div id="next-previous-nav">
    	<?php if (previous_post_link_plus( array(
                             'order_by' => 'post_date',
                             'loop' => false,
    			 'link' => "Previous",
                             'tooltip' => 'Previous letter',
    			 'in_cats' => '35505, 42971, 42973',
                             'ex_cats_method' => 'diff',
                        ) ) );
    			else
    			echo "<em>This is the first page in this section</em>";
    			?> |
    	<?php if (next_post_link_plus( array(
                             'order_by' => 'post_date',
                             'loop' => false,
    			 'link' => "Next",
                             'tooltip' => 'Next letter',
    			 'in_cats' => '35505, 42971, 42973',
                             'ex_cats_method' => 'diff',
                        ) ) );
    			else
    			echo "<em>This is the last letter in the section</em>";
    			?>
    	</div>

    Thanks for the great plugin and taking the time to help me out!

  4. ambrosite
    Member
    Plugin Author

    Posted 2 years ago #

    I've been trying to figure out the best way to approach this. I think that if I were to take the array intersection of in_same_cat and in_cats, rather than simply disabling in_same_cat, that would probably give you the result you want. In fact, I can see no reason not to do that, so I will make the change in the next version of the plugin. I don't know when it will be coming out though, not for a while yet.

    If you'd rather not wait -- and if you don't mind hacking the plugin code -- I can give you a patch to make the change now. Let me know.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic