1

looking to create a page that will show all posts from several categories. for example lets say I want all of my posts from category 1, 5, and 9 together. the posts on the page should be ones from any of those categories and aren't required to be in multiple of them or all of them. is it possible to do this?

1 Answer 1

2

To display a custom query in a single page you would need to create a new page template and assign that to a page.

  1. Create a file in your theme's main folder and call it multiple-categories.php
  2. Paste the following code in the file

    <?php
    /* Template Name: Multiple Categories */
    
    get_header();
    
    $args = array(
        'cat' => '1, 5, 9',
        'posts_per_page' => -1,
    );
    
    $my_posts = new WP_Query( $args );
    
    if( $my_posts->have_posts() ){
        while( $my_posts->have_posts() ){
            $my_posts->the_post();
            //Echo the post
        }
    }
    wp_reset_postdata();
    
    get_footer();
    
  3. Create a new page and in the template field select "Multiple categories".

Visiting that page you should see the articles from any of those categories. The template file and name is just an example and can be changed at will without using the default ones listed here https://developer.wordpress.org/themes/basics/template-hierarchy/

More details about the arguments for the query relative to categories can be found here: https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

5
  • ah.. so I need premium to do this? to customize the css?
    – Zak
    Commented May 31, 2019 at 20:03
  • What do you mean with "I need premium to do this"? For the CSS you can add any style to your theme's style.css file
    – freejack
    Commented May 31, 2019 at 20:11
  • I can't seem to access any CSS editing, where is this located? I am going to Design > Themes > Customize > CSS and it says "Purchase premium to activate CSS customization"
    – Zak
    Commented May 31, 2019 at 20:25
  • My instruction presumes that you have access to your themes' files and can create or change them. It is not something you can do from the admin side. Sorry!
    – freejack
    Commented May 31, 2019 at 20:37
  • No worries thank you for your help!
    – Zak
    Commented May 31, 2019 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.