Support » Fixing WordPress » Create a link to page that displays posts from 2 categories

  • Hi thanks for viewing.

    I want to create links ‘Science News’ and ‘Science Events’ There will also be Geography events and geography news etc. for various school subjects so I need to query 2 categories at a time.

    So it would be like list_categories when you hit the category link it displays everything in one category. But I’d like one link to display results that belong to both Science AND News categories. Any ideas??

    Thanks in advance!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Matt Knowles

    (@aestheticdesign)

    There are plugins that can do that. Search the repository for List Categories and you should find some capable of that.

    Howdy, you can certainly do this.
    You need to learn a bit about making your own WP_Query, and use some Category parameters.
    Start here:
    https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

    One way to make use of a custom WP_Query in your case is to create a custom page template, and within that template run the custom query.
    For custom page templates, start here:
    https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/#Custom_Page_Template

    Good luck!

    Thread Starter jfkweb

    (@jfkweb)

    Great thank you guys I’ll have alook at those options.

    Paul do you think creating a page template is the only way of achieving this? There are 24 subjects so would require a lot of pages.

    Thanks for the replies.

    Actually, my page template suggestion is probably not necessary. I need to clarify what you want here.

    I’m thinking you could just use hierarchical categories to get what you want without any real custom coding.

    Example:

    Science (root-level category)
    * Science News (child of Science)
    * Science Events (child of Science)

    Geography
    * Geography News
    * Geography Events

    … and so on.

    That way, you can get all Science stuff, all Science News, or all Science Events with just category links.

    Will that do what you want, or are we not quite there yet?
    Let me know.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Create a link to page that displays posts from 2 categories’ is closed to new replies.