Create a Page Template
- Create a new page in your theme’s directory called page-articles.php; for example,
/wp-content/themes/my-genesis-theme/page-articles.php - Paste the following code into page-articles.php:
<?php /* Template Name: Articles Template */ /** Replace the standard loop with our custom loop */ remove_action( 'genesis_loop', 'genesis_do_loop' ); add_action( 'genesis_loop', 'wnd_do_custom_loop' ); function wnd_do_custom_loop() { global $paged; // current paginated page global $query_args; // grab the current wp_query() args $args = array( 'cat' => 8, /* shows all posts and child posts from category id */ 'paged' => $paged, // respect pagination ); /* If you want to show posts from a category only and no subcategory posts, use 'category_name' => 'category-slug', instead of 'cat' => 8, for example, 'category_name' => 'articles', */ genesis_custom_loop( wp_parse_args($query_args, $args) ); } genesis();
- Change the number in ‘cat’ => 8 to the number of the category you want to use.
Note: To find the category number, go to Posts > Categories and click the category link. In your browser url field, you will see a URL that looks like the following:
/wp-admin/edit-tags.php?action=edit&taxonomy=category&tag_ID=33&post_type=post
In the example above, the category number is 33. - If you want, you can change the template name. In the example, modify this line:
/* Template Name: Articles Template */.
Articles Template is the template name. This is NOT related to the name we gave the php file. - Save the file.
Leave a Reply