Trong phần nhận xét Cách chỉ hiển thị tiêu đề Bài đăng trên các trang danh mục trong bài viết Genesis , một người dùng đã hỏi:
Đây gần như là chính xác những gì tôi cần. Tuy nhiên, các bài đăng trên blog của khách hàng của tôi là những nghiên cứu kinh thánh dài REAAAALLLLYYYY. Vì vậy, trên trang blog chính (không phải là trang chủ - mà là một mục menu khác), tôi chỉ muốn hiển thị một bài đăng trên blog. Nhưng đối với danh sách danh mục, tôi muốn hiển thị tất cả các tiêu đề trên một trang cho danh mục đó. Có cách nào để làm việc này không?
Tôi đã ghi lại một video truyền hình trong đó bạn có thể thấy cách thực hiện ở trên.
Lưu ý: Trong video, bạn có thể thấy rằng tôi đã thêm mã hành động vào bên trong functions.php. Vì chúng tôi muốn điều này chỉ cho các kho lưu trữ danh mục, thay vào đó, mã phải được đặt trong category.php (bất kỳ nơi nào giữa thẻ PHP mở và lệnh gọi hàm genesis () đóng).
Chỉ hiển thị một mục trên trang Bài đăng
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' );
}
}
Chỉ hiển thị tiêu đề cho Bài đăng trên Kho lưu trữ Danh mục
category.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;
}