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
To display a custom query in a single page you would need to create a new page template and assign that to a page.
- Create a file in your theme's main folder and call it multiple-categories.php
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();
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
-
-
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– freejackCommented 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"– ZakCommented 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!– freejackCommented May 31, 2019 at 20:37
-