Tuy nhiên, tôi thực sự muốn nội dung có chiều rộng đầy đủ. Có thể điều chỉnh mẫu để thanh bên chính chỉ bắt đầu khi các bài đăng trên blog bắt đầu không?
Đây hoàn toàn sẽ là một mẫu trang tùy chỉnh. Vì vậy, tạo một tệp “template_fwcblgpost.php” và thêm đoạn mã sau. Tệp mới này sẽ tải lên trong thư mục chủ đề con của bạn thông qua FTP hoặc Cpanel / Trình quản lý tệp.
/* Template Name: Full Width Content with Blog Posts */ //* Add outreach-pro-home body class add_filter( 'body_class', 'custom_body_class' ); function custom_body_class( $classes ) { $classes[] = 'fwc-blgpost'; return $classes; } remove_action('genesis_loop', 'genesis_do_loop'); // Removing default loop add_action('genesis_before_content', 'genesis_do_loop'); // Repositioning the page content // Fix for the WordPress 3.0 "paged" bug. $paged = 1; if ( get_query_var( 'paged' ) ) { $paged = get_query_var( 'paged' ); } if ( get_query_var( 'page' ) ) { $paged = get_query_var( 'page' ); } $paged = intval( $paged ); if( $paged > 1 ){ remove_action('genesis_before_content', 'genesis_do_loop'); } // Add your grid loop add_action( 'genesis_after_loop', 'gd_custom_grid_loop_helper' ); remove_action( 'genesis_after_endwhile', 'genesis_posts_nav' ); add_action( 'genesis_after_endwhile', 'genesis_custom_tpl_posts_nav' ); $first_page_limit = 6; $post_per_page = $next_page_limit = 8; /** Add support for Genesis Grid Loop **/ function gd_custom_grid_loop_helper() { global $paged, $first_page_limit, $next_page_limit, $post_per_page; if ( function_exists( 'genesis_custom_loop' ) ) { if( $paged == 1 ) $post_per_page = $first_page_limit; $args = array( 'post_type' => 'post', 'showposts' => $post_per_page, 'paged' => $paged); if( $paged > 1 ) $offset = ( $next_page_limit * ( $paged - 2 ) + $first_page_limit ); if( intval( $offset ) > 0 ) $args['offset'] = $offset; //* Add even/odd post class add_filter( 'post_class', 'gd_grid_post_class' ); genesis_custom_loop($args); }else { //* Add even/odd post class add_filter( 'post_class', 'gd_grid_post_class' ); genesis_standard_loop(); } remove_filter( 'post_class', 'gd_grid_post_class' ); } function gd_grid_post_class( $classes ) { global $wp_query; $classes[] = 'one-half'; $classes[] = ($wp_query->current_post % 2 == 0) ? 'first' : ''; return $classes; } function genesis_custom_tpl_posts_nav(){ if ( 'numeric' === genesis_get_option( 'posts_nav' ) ) genesis_custom_tpl_numeric_posts_nav(); else genesis_prev_next_posts_nav(); } function genesis_custom_tpl_numeric_posts_nav() { if( is_singular() ) return; global $wp_query, $paged, $first_page_limit, $next_page_limit; //* Stop execution if there's only 1 page if( $wp_query->max_num_pages <= 1 ) return; $max = intval( $wp_query->max_num_pages ); if( $paged == 1 ): $found_posts = $wp_query->found_posts - $first_page_limit; $max = $wp_query->max_num_pages = intval( ceil( $found_posts / $next_page_limit ) ) + 1; endif; //* Add current page to the array if ( $paged >= 1 ) $links[] = $paged; //* Add the pages around the current page to the array if ( $paged >= 3 ) { $links[] = $paged - 1; $links[] = $paged - 2; } if ( ( $paged + 2 ) <= $max ) { $links[] = $paged + 2; $links[] = $paged + 1; } genesis_markup( array( 'html5' => '<div %s>', 'xhtml' => '<div class="navigation">', 'context' => 'archive-pagination', ) ); echo '<ul>'; //* Previous Post Link if ( get_previous_posts_link() ) printf( '<li class="pagination-previous">%s</li>' . "\n", get_previous_posts_link( apply_filters( 'genesis_prev_link_text', '«' . __( 'Previous Page', 'genesis' ) ) ) ); //* Link to first page, plus ellipses if necessary if ( ! in_array( 1, $links ) ) { $class = 1 == $paged ? ' class="active"' : ''; printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' ); if ( ! in_array( 2, $links ) ) echo '<li class="pagination-omission">…</li>'; } //* Link to current page, plus 2 pages in either direction if necessary sort( $links ); foreach ( (array) $links as $link ) { $class = $paged == $link ? ' class="active"' : ''; printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link ); } //* Link to last page, plus ellipses if necessary if ( ! in_array( $max, $links ) ) { if ( ! in_array( $max - 1, $links ) ) echo '<li class="pagination-omission">…</li>' . "\n"; $class = $paged == $max ? ' class="active"' : ''; printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max ); } //* Next Post Link if ( get_next_posts_link() ) printf( '<li class="pagination-next">%s</li>' . "\n", get_next_posts_link( apply_filters( 'genesis_next_link_text', __( 'Next Page', 'genesis' ) . '»' ) ) ); echo '</ul></div>' . "\n"; } //* Run the Genesis loop genesis();
Đối với một số chủ đề cần một số tinh chỉnh CSS. Tôi đã áp dụng CSS sau trong tệp style.css của mình:
.fwc-blgpost article.page{ background-color: #fff; padding: 40px; }