In the comments section my How to show only Post titles on category pages in Genesis article, a user asked:
This is almost exactly what I need. However, my client’s blog posts are REAAAALLLLYYYY long bible studies. So on the main blog page (which is not the home page – it’s another menu item), I just want to show one blog post. But for the category listings, I want to show all titles on one page for that category. Is there a way to do this?
Posts page:
Category archives:
I have recorded a screencast in which you can see how the above can be done.
Note: In the video you can see that I have added the actions code inside functions.php. Since we want this only for category archives, the code should instead be placed in category.php (anywhere between the opening PHP tag and closing genesis() function call).
Showing just one entry on the Posts page
add_action( 'pre_get_posts', 'sk_change_blog_posts_per_page' ); | |
/** | |
* Change Posts Per Page for Posts page | |
* | |
* @author Bill Erickson | |
* @link http://www.billerickson.net/customize-the-wordpress-query/ | |
* @param object $query data | |
* | |
*/ | |
function sk_change_blog_posts_per_page( $query ) { | |
if( $query->is_main_query() && !is_admin() && is_home() ) { | |
$query->set( 'posts_per_page', '1' ); | |
} | |
} |
Displaying only titles for Posts on Category Archives
category.php:
<?php | |
remove_action( 'genesis_entry_header', 'genesis_do_post_format_image', 4 ); | |
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 ); | |
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 ); | |
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 ); | |
remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 ); | |
remove_action( 'genesis_entry_content', 'genesis_do_post_content' ); | |
remove_action( 'genesis_entry_content', 'genesis_do_post_content_nav', 12 ); | |
remove_action( 'genesis_entry_content', 'genesis_do_post_permalink', 14 ); | |
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 ); | |
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 ); | |
remove_action( 'genesis_entry_footer', 'genesis_post_meta' ); | |
remove_action( 'genesis_after_entry', 'genesis_do_author_box_single', 8 ); | |
remove_action( 'genesis_after_entry', 'genesis_get_comments_template' ); | |
add_action( 'loop_start', 'sk_opening_articles_tag' ); | |
function sk_opening_articles_tag() { | |
echo '<div class="articles">'; | |
} | |
add_action( 'loop_end', 'sk_closing_articles_tag' ); | |
function sk_closing_articles_tag() { | |
echo '</div>'; | |
} | |
genesis(); |
style.css:
.category .content .entry { | |
margin-bottom: 0; | |
padding-bottom: 0; | |
padding-top: 20px; | |
} | |
.category .content .entry-title { | |
font-size: 24px; | |
} | |
.category .articles { | |
padding-top: 20px; | |
padding-bottom: 40px; | |
background-color: #fff; | |
} |
References:
www.billerickson.net/customize-the-wordpress-query/
https://sridharkatakam.com/sublime-text-snippets-for-genesis/
wp-content/themes/genesis/lib/structure/post.php
Can’t wait to try this tomorrow! Thank you, Sridhar!
Thanks for the tutorial, Sridhar! Very useful from SEO standpoint as well.
That was freakin’ awesome. Client is so happy!
Sridhar, this is just what I need but for my CPTs not posts. I have the CPT’s: books, article etc. and they are files under categories such as sales or leadership. When I look at a category archive page for say leadership, I’d like a list of titles, for any of the books or articles. How would I achieve this? Thanks in advance for your help.
Sridhar, I realised my mistake I hadn’t allowed for CPT’s to be included in category archives in my functions file! I now have my CPTs showing up.
Now on my category archives page I would like to have the footer and top nav displaying the same as my other pages; how would I achieve this? (nothing I have tried has worked) Thanks.
That should happen automatically. Can you provide the URL of any category archive in your site?
Sridhar I have fixed it now thank you, using this code from Bill Erickson, which I found on your site! I changed it to see if my CPT’s would show up on my archive pages:
add_action( ‘pre_get_posts’, ‘cpt_entries_and_posts_archives’ );
function cpt_entries_and_posts_archives( $query ) {
if( $query->is_main_query() && !is_admin() && is_archive( ) ) {
$query->set( ‘posts_type’, array( ‘post’, ‘articles, ‘books’, ‘ebooks’ );
}
}
Now my CPT’s show up on my category page. I am trying to build a library and now will try and build a category template to show the CPT’s in a 3 column list, ideally with a dashicon or colour code to show what CPT they are! And content above and below.