This tutorial provides the code which works in any theme to enable you to display a unordered or ordered list of post titles assigned to one specific category.
Here’s the result which you can easily modify using the CSS included in this post.
Note: Only works within the loop.
Code Installation
- Create a new file named catposts.php using a code editor like Notepad++ and copy & paste the PHP code from the Gist labelled catposts.php into the new file then upload it to your child themes root directory.
- Copy the CSS code from the Gist labelled style.css and paste it at the end of your child themes style.css file before the start of your Media Queries section.
You’ll then need to use one of the following 2 methods to display your list in your theme.
Display List
If your theme includes hooks or you understand WordPress hooks, you can simply hook in the get_template_part tag from your functions file like this example which works in Genesis.
add_action ( 'genesis_before_entry', 'popular_posts_before_content' );
function popular_posts_before_content() {
if ( is_singular('post') ) {
get_template_part( 'catposts' );
}}
Otherwise you can add the code directly to a template file with or without conditional tags:
<?php get_template_part( 'catposts' ); ?>
You could then add some style by using Dashicons to style your list.
Was This Tutorial Helpful?