Jump to content

- - - - -

Make PostNav category-specific?

postnav category categories

  • Please log in to reply
2 replies to this topic

#1 caspersjan†


    Super Member

  • DMS Subscriber†
  • 202 posts
  • Country: Country Flag

Posted 27 August 2014 - 11:52 AM

Dear Pagelines team, leafing through the Forums, I found an old solution to a problem I am facing: How to make the PostNav section include posts from the same category only? This is the suggested fix:


BEST ANSWER The Farside14 August 2012 - 04:06 AM

I seem to have figured it out, but if this is wrong or if there is another way, let me know.
Here is what I've done in the sections directory for postnav section.php

<span class="previous"><?php previous_post_link('%link', $link='%title', $in_same_cat = true); ?></span>
                <span class="next"><?php next_post_link('%link', $link='%title', $in_same_cat = true); ?></span>


I found the postnav section.php (wp-content/themes/dms/dms/sections/navbar). Do I just add the above code? And would it still be valid in DMS2 (it's ancient - from 2012!) I am hesitant as I am always afraid to break things when dealing with PHP. Or is there another way, a plugin or child theme that lets me add this in a safer way (and one that may withstand upgrades)? 


Thank you for your help and advice. It is always a pleasure working with Pagelines, every day!  I should say that more often, but of course yet again it is only when there is a problem that I get in touch...


Yours faithfully, Jan.

#2 Danny


    Is Awesome!

  • Moderators
  • 19770 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 27 August 2014 - 01:03 PM

Hi Jan,


The best thing to do when doing something like this is for you to create a child of that section via a child theme. Then replace the code you and see if it works, I can't guarantee it unfortunately.


To create a child section, first you're going to need a child theme, you're free to use mine here - http://dannyholt.github.io/skeleton download the advanced version which contains a section directory.


Then you're going to need to copy the PostNav section folder into your child themes section directory. Then make your necessary changes, this will override the core section with the child.


If the code doesn't work, please let me know and I will add it to our feature request tracker.

#3 caspersjan†


    Super Member

  • DMS Subscriber†
  • 202 posts
  • Country: Country Flag

Posted 27 August 2014 - 01:42 PM

Thank you, Danny, for this advice and for the child theme link. I will try my hand at this - it will be good to learn about these things anyway! A built-in feature for PostNav would be great though. There are a few previous-next-post-navigation plugins that do this, but they are old and have not been maintained. Maybe that means that it is a rare request. But it would be very useful. Anyway, I'll let you know how I get on. Yours faithfully, Jan.

Also tagged with one or more of these keywords: postnav, category, categories