• Hi,
    I would like to know if it is possible that the Previuos Post and Next Post bar navigation at the end of every post show only posts from the same category of the one displayed and not from all categories on my website.

    Thank you

Viewing 9 replies - 1 through 9 (of 9 total)
  • sacredpath

    (@sacredpath)

    Automattic Happiness Engineer

    If your posts have only a single category assigned to them, you should be able to find your answer in Codex Function Reference/previous post link.

    I would suggest creating and using a Child theme so that your changes are not overwritten by an theme update. See in_same_term and taxonomy.

    Thread Starter mm81

    (@mm81)

    Thank you sacredpath but I don’t think it can work, for me. My posts have 2 categories assigned to them. Is there any other way i can do it?

    sacredpath

    (@sacredpath)

    Automattic Happiness Engineer

    Right off hand, I’m not sure what you would use as a criteria to determine what category “next/previous post” would take a user to if there are two or more categories assigned to a post. Alphabetical? Random? I guess you could somehow pull all posts from all the categories assigned to that post and then pull up the next/previous within that array, but then on the next post, it’s possible one of the categories may be different on that post, so you then have to create another array and choose one from that array.

    You can use categories in your navigation and then users can choose which category they are interested in and then they can read through the posts in that category. Of course once they go to a single post page, the previous/next links will take them to the next chronological post, not the next post in that category. They would have to use he browser back button to get back to the category page.

    Thread Starter mm81

    (@mm81)

    Hi there,
    i try to explain myself a little bit better!
    I use my website as a portfolio, my work is made of “Artwork” and “Photo”.

    So, under the category “Artwork” there are other subcategories, the same is for “Photo” cataegory, in which for example i have “Black & White” pictures and “mixed” as sub categories.

    The thing is that i don’t want the post i mark as “Photo” to be displayed under the posts in “Artwork” but i do not know how to do this

    sacredpath

    (@sacredpath)

    Automattic Happiness Engineer

    Thanks for the explanation. Is your site live right now so that I can take a look at it? If so, please post a link. There might be some CSS trickery we can use to exclude by category, but I will have to do some testing.

    Thread Starter mm81

    (@mm81)

    Thank you sacredpath, the website is https://www.manuelamedici.it/

    sacredpath

    (@sacredpath)

    Automattic Happiness Engineer

    Ok, we can exclude Black & White and Other from Photo, which is what I think you want. What we would do would be to use the category class from the opening body selector and then the article HTML tag and the article category class like below.

    .category-photo article.category-black-white, .category-photo article.category-other {
        display: none;
    }

    For Artwork, it would be similar, but the selectors would of course change. Example:
    .category-artwork article.category-awakenings...

    You will need to include the additional selectors for the other artwork subcategories.

    Thread Starter mm81

    (@mm81)

    Thank you,can you tell me which CSS file in the Picotrico theme controls the Post navigation and where i should add these lines?

    sacredpath

    (@sacredpath)

    Automattic Happiness Engineer

    I would suggest creating a child theme so that any customizations you make will not be overwritten by a future theme update. Alternately you can use the Edit CSS function in the Jetpack plugin, or use one of the other Custom CSS plugins that will keep CSS changes from being overwritten.

    Jetpack plugin
    Child Themes
    Child Theme creation plugins
    Custom CSS plugins

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Display Previus and Next post only from same category’ is closed to new replies.