Community Forums › Forums › Archived Forums › Design Tips and Tricks › portfolio subnav conditional by category?
- This topic has 5 replies, 2 voices, and was last updated 9 years, 10 months ago by David Chu.
-
AuthorPosts
-
May 5, 2014 at 11:47 am #103719design_agencyMember
hi.
im trying to add previous / next navigation on just one category within my portfolio. i've followed this tutorial but can not seem to figure out the conditional tags (as of now, previous / next links are appearing on all of my portfolio pages.)
i created a category for my portfolio pages called "glass" and have tried every combination i can think of to get it to work.
code is hereanyone know how i can get this to work?
many thanks,
emilyMay 5, 2014 at 2:52 pm #103752David ChuParticipantHi,
I liked this question. Your syntax style is a little different from mine, but it works fine. I was actually going to use is_category first, but that's trickier because it returns an array that you'd have to deal with. You'll see where I added in_category below, and it will take a slug, and category number, or a category name - nicely versatile.Let's see if this forum software butchers my code. 🙂 Yes, it did. I put it in a gist comment. But I think you get the idea.
function wpsites_npp_navigation_links() { if( 'portfolio' == get_post_type() && is_single() && in_category('category-1') ) {?> <?php previous_post('« « %', 'Previous', 'no'); ?> | <?php next_post('% » » ', 'Next', 'no'); ?> <?php } } add_action('genesis_entry_content', 'wpsites_npp_navigation_links', 5 );
Cheers, Dave
Dave Chu · Custom WordPress Developer – likes collaborating with Designers
May 6, 2014 at 7:50 am #103827design_agencyMemberhi dave,
thanks for taking a look at this!
i gave your suggestion a go but no luck. just to be sure, here is the code i used.
function wpsites_custom_post_type_links() { if( 'portfolio' == get_post_type() && is_single() && in_category('glass')) {?> <?php previous_post('« « %', 'Previous Slide Show', 'no'); ?> | <?php next_post('% » » ', 'Next Slide Show', 'no'); ?> <?php } } add_action('genesis_entry_content', 'wpsites_custom_post_type_links', 5 );
do you know a better way to do this? it seems like this should be working since im trying to link between the same category, but perhaps there's a better way?
any insight is appreciated,
emilyMay 6, 2014 at 8:40 am #103831David ChuParticipantHmmm...
I'm not sure. One of those classics where it "works for me", but not in your situation for some reason. I wasn't using a 'portfolio' post type in my test. I did my test using a post_type of 'post', because I don't have a portfolio post_type. You could give that a try, and use categories that you know are populated. If that works, then something else is out-of-sync.I'm also handicapped by not being on your site and in your code. It seems to me your stuff should work great as long as there's no typo anywhere, and that your data matches those specs.
Just to rule out the obvious... since you have "is_single()", I take it that you're viewing a single "portfolio post" to do your test, right?
If all else fails, you could take a different tack and use categories in your menu. That's certainly an easy way to bring up everything in a certain grouping.
Hope that helps a bit,
Dave
Dave Chu · Custom WordPress Developer – likes collaborating with Designers
May 6, 2014 at 12:35 pm #103879design_agencyMemberhi david, you've given me a lot of good leads, yet nothing yet has worked (boo!)
im new to the hooks and filters side of development, so nothing is obvious to me. what should i change that "is_single()" tag to if these are indeed portfolio posts? not sure this will make a difference but here's a link to the page i'm working on.
thanks again for taking the time,
emilyMay 7, 2014 at 7:37 am #104043David ChuParticipantEmily,
That's a horse of a different color. 🙂 (I think is_single is good, btw).If I'm following you (it's certainly possible that I'm not, this is very complex), I'm thinking you may want to add the "in_same_cat" parm in there. So I'm thinking you could have a 'yes' after each 'no', like this:
... 'no', 'yes'); ?>
I think that should limit it to the same category as the particular Post you're looking at. Unless something else is interfering. 🙂
More on that stuff here.Cheers, Dave
Dave Chu · Custom WordPress Developer – likes collaborating with Designers
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.