category page modifications (16 posts)

  1. benbt-japan
    Posted 9 years ago #

    blog url : http://www.language-global.com/blog
    theme : default theme

    Hi. Greatly enjoying this really excellent software, but still very green about how everything works. I am working through the documentation as best as I can, but I hope someone out there could give me some pointers about the following question:

    (1) My posts are divided into a number of categories. I would like these categories to be kept completely separate throughout the blog. So, for example, if someone clicks on category 2, then chooses a post to read, I don't want the 'previous' and 'next' links at the top of the page to link to posts from categories 1 or 3.

    I am using the brilliant category visibility plug-in, which has given me some control over how things display, but doesn't have an option to keep categories completely separate.
    I will be very grateful for any pointers as to how to do this - even a link to a page in the documentation section would be appreciated.

  2. benbt-japan
    Posted 9 years ago #

    OK. I found something helpful here : http://codex.wordpress.org/Template_Tags/next_post
    and here : http://codex.wordpress.org/Template_Tags/previous_post

    Can someone just confirm that the code I will need to have is:
    <?php previous_post('%','&laquo','in_same_cat','yes'); ?>
    <?php next_post('%','&raquo','in_same_cat','yes'); ?>

  3. benbt-japan
    Posted 9 years ago #

    OK. I think I got it now...

    <?php previous_post('','','','yes'); ?>
    <?php next_post('','','','yes'); ?>

    This should only show links to next and previous posts in the same category as the currently-selected post.

    Am I right? (I'm going to try it out when I get access to my own pc back after the weekend, but it would be nice to know if I've got it right or not in advance..)

  4. benbt-japan
    Posted 9 years ago #

    Well, I've waited nearly a week for a reply to this post, but nothing. Is my question really so undeserving of attention!!

    I've tried editing my single.php file to :
    <div class="alignleft"><?php previous_post_link('&laquo; %link','','','yes') ?></div>
    <div class="alignright"><?php next_post_link('%link &raquo;','','','yes') ?></div>

    ...but the result is that now in single page mode no links at all are shown at the top of the page. I've read the documentation and I've tried to follow the directions. I believe the final 'yes' option should be the in_same_cat parameter that is set by default to 'no'. By changing this parameter I should be able to get the links at the top of the page to only point to posts in the same category as the current post.

    Please - someone give me an answer!

  5. benbt-japan
    Posted 9 years ago #

    ...er...pretty please with cherries on top!

  6. vicar
    Posted 9 years ago #

    I'm sorry that I can't help you at all, but I was looking through the posts to find information about making each category have a different look when I saw all of these posts made by you....with no responses! I'm sorry...wish I had some expertise to offer. Maybe someone will come soon!

    Good luck!

  7. benbt-japan
    Posted 9 years ago #

    Another week has passed, and still no help for poor me! If you're reading this and understand the question I am asking about, please post. I really would appreciate it.

  8. moshu
    Posted 9 years ago #

    It isn't "next_post_link" as you have it: it is "next_post" what you linked earlier - isn't it?

    next_post_link has a different way of putting the parameters:

  9. benbt-japan
    Posted 9 years ago #

    Thanks Moshu - searching around from the link you gave I see that previous_post and next_post are being deprecated in favour of next_post_link and previous_post_link. I now understand the syntax for next_post_link, but a search for previous_post_link turned up nothing so I will just have to assume that the syntax is the same for both.
    Thanks again for pointing me in the right direction.

  10. benbt-japan
    Posted 9 years ago #

    I changed :
    <?php previous_post_link('&laquo; %link') ?>
    to :
    <?php previous_post_link($format='&laquo; %link', $in_same_cat=true) ?>

    And as a result, the link changed to '< 1', and it was linking to a post in another category... A failure on all counts.

    I know I must be doing something wrong, but I followed the instructions in the link you gave to the letter. My blog is running V.2.0.2. of WP - would the problem be solved by upgrading to 2.0.4.? I just haven't got round to it yet...

  11. benbt-japan
    Posted 9 years ago #

    OK. I've upgraded to 2.0.4.
    Here's my problem :
    This code in the single post file...
    <div class="alignleft"><?php previous_post_link('&laquo; %link') ?></div>
    <div class="alignright"><?php next_post_link('%link &raquo;') ?></div>

    ...is different to the format for parameters given in the codex. Can anyone tell me how to set it so that only posts from the same category are linked to? I tried adding $in_same_cat=true but that did not work (as detailed above).
    Thanks loads to anyone who can help with this.

  12. benbt-japan
    Posted 9 years ago #

    I'm still hoping that someone can help me with this previous_post_link and next_post_link syntax.

    Thanks in advance for any help.

  13. DorianWar
    Posted 9 years ago #


    Did you find a solution to the problem?

    This is something I want to do with my WordPress installs. I try to keep everything linked in the samed "themed" category.

    If you found out a fix. please post it.


  14. DorianWar
    Posted 9 years ago #

    As soon as I posted this, I found a fix.

    Try this:

    <?php previous_post_link($format='&laquo %link', $link='%title', $in_same_cat = true); ?>


  15. AUSR
    Posted 9 years ago #

    I am at a total and complete loss after reading all of this and then some, but if someone has actually changed the code some place to make this work, I'm very interested in knowing what I need to change and where. The visitors to my site are not happy campers because previous and next do not point to posts within the category they are browsing.


  16. AUSR
    Posted 9 years ago #

    Okay, figured it out... problem fixed!
    See code below:

    <?php next_post_link($format='<li class="right">&raquo %link', $link='%title', $in_same_cat = true); ?>
    <?php previous_post_link($format='<li class="left">&laquo %link', $link='%title', $in_same_cat = true); ?>


Topic Closed

This topic has been closed to new replies.

About this Topic