Tạo Featured Section 2 cột trên Theme GoMedia
- Nhận đường liên kết
- X
- Ứng dụng khác
Ở bài viết trước mình đã có bài viết sử dụng Theme GoMedia trên WordPress và khắc phục lỗi khung soạn thảo trên Theme GoMedia. Tuy nhiên, trên Theme GoMedia có một tính năng đó là Featured Section. Tính năng này giúp hiển thị bài viết ở đầu trang chủ dựa vào Tag. Mặc định nó chỉ hiển thị được có 3 bài viết nhưng nếu bây giờ bạn muốn nó hiển thì 6 bài viết thì phải làm sao? Và liệu bạn có muốn xoá cái Slide bên trái đi và thêm vào đó 3 bài viết nữa không? Nếu có thì hãy cùng xem qua bài tạo Featured Section 2 cột trên Theme GoMedia này nhé!
Các bạn truy cập vào Dashboard -> Appearance -> Editor -> sau đó mở file front.php lên. Và thay thế toàn bộ bằng đoạn sau và lưu lại:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | <?php get_header(); ?> <div class="container"> <div class="row"> <div id="content" class="col-md-9"> <?php if ( of_get_option( 'gomedia_featured_posts', '1' ) ) { ?> <section id="featured-content" class="row clearfix"> <?php $tag = of_get_option( 'gomedia_featured_tag' ); ?> <?php $featured = get_posts( array( 'posts_per_page' => 3, 'tag_id' => $tag ) ); ?> <?php if ( $tag && $featured ) : ?> <div id="featured-right" class="col-md-6"> <ul> <?php foreach ( $featured as $post ) : setup_postdata( $post ); ?> <li class="plain-item <?php if ( ++$i == 3 ) { echo 'last-item'; } ?> clearfix"> <a href="<?php the_permalink(); ?>" rel="bookmark"> <?php if ( has_post_thumbnail() ) : ?> <?php the_post_thumbnail( 'gomedia-featured-small', array( 'class' => 'entry-thumb', 'alt' => esc_attr( get_the_title() ) ) ); ?> <?php endif; ?> <div class="plain-title"> <?php the_title( '<h2 class="entry-title">', '</h2>' ); ?> <div class="entry-meta"><?php printf( __( 'by %s', 'gomedia' ), esc_attr( get_the_author() ) ) ?></div><!-- .entry-meta --> </div><!-- .carousel-caption --> </a> </li> <?php endforeach; ?> </ul> </div> <?php endif; wp_reset_postdata(); ?> <?php $featured2 = get_posts( array( 'posts_per_page' => 3, 'offset' => 3, 'tag_id' => $tag ) ); ?> <?php if ( $tag && $featured2 ) : ?> <?php $i = 0; ?> <div id="featured-right" class="col-md-6"> <ul> <?php foreach ( $featured2 as $post ) : setup_postdata( $post ); ?> <li class="plain-item <?php if ( ++$i == 3 ) { echo 'last-item'; } ?> clearfix"> <a href="<?php the_permalink(); ?>" rel="bookmark"> <?php if ( has_post_thumbnail() ) : ?> <?php the_post_thumbnail( 'gomedia-featured-small', array( 'class' => 'entry-thumb', 'alt' => esc_attr( get_the_title() ) ) ); ?> <?php endif; ?> <div class="plain-title"> <?php the_title( '<h2 class="entry-title">', '</h2>' ); ?> <div class="entry-meta"><?php printf( __( 'by %s', 'gomedia' ), esc_attr( get_the_author() ) ) ?></div><!-- .entry-meta --> </div><!-- .carousel-caption --> </a> </li> <?php endforeach; ?> </ul> </div> <?php endif; wp_reset_postdata(); ?> </section><!-- #featured-content --> <?php } ?> <?php $ad = of_get_option( 'gomedia_home_ads' ); ?> <?php if ( $ad ) { ?> <div class="home-ad"> <?php echo stripslashes( $ad ); ?> </div> <?php } ?> <main id="recent-content-1" class="site-main content-loop" role="main"> <h3 class="section-title"><?php _e( 'News', 'gomedia' ); ?></h3> <?php $latest = get_posts( array( 'posts_per_page' => 3 ) ); ?> <?php if ( $latest ) : ?> <?php $i = 0; ?> <?php foreach ( $latest as $post ) : setup_postdata( $post ); ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?> <?php if ( ++$i == 3 ) { echo 'style="border-bottom: none;"'; } ?>> <?php if ( has_post_thumbnail() ) : ?> <a class="hidden-xs" href="<?php the_permalink(); ?>" rel="bookmark"> <div class="entry-thumb-wrapper"> <?php the_post_thumbnail( 'gomedia-post-thumb', array( 'class' => 'entry-thumb', 'alt' => esc_attr( get_the_title() ) ) ); ?> <?php echo gomedia_get_post_format_icons(); // get the post format icons. ?> </div><!-- .entry-thumb-wrapper --> </a> <?php endif; ?> <header class="entry-header"> <?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?> <div class="entry-meta"> <?php gomedia_posted_on(); ?> </div><!-- .entry-meta --> </header><!-- .entry-header --> <div class="entry-excerpt"> <?php the_excerpt(); ?> </div><!-- .entry-excerpt --> </article><!-- #post-## --> <?php endforeach; ?> <?php endif; wp_reset_postdata(); ?> </main><!-- .site-main --> </div><!-- #content --> <?php get_sidebar( 'home-top' ); // Loads the sidebar-home-top.php templates. ?> </div><!-- .row --> </div><!-- .container --> <?php if ( of_get_option( 'gomedia_latest_videos', '1' ) ) { ?> <div id="carousel-1" class="carousel-loop"> <div class="container"> <?php $limit = (int) of_get_option( 'gomedia_latest_videos_num', 10 ); $args = array( 'tax_query' => array( array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array( 'post-format-video' ) ) ), 'posts_per_page' => $limit ); $video = get_posts( $args ); ?> <?php if ( $video ) : ?> <h2 class="section-title"><?php _e( 'Latest Videos', 'gomedia' ); ?></h2> <div class="jcarousel jcarousel-carousel"> <ul> <?php foreach ( $video as $post ) : setup_postdata( $post ); ?> <li> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <?php if ( has_post_thumbnail() ) : ?> <a href="<?php the_permalink(); ?>" rel="bookmark"> <?php the_post_thumbnail( 'gomedia-carousel-thumb', array( 'class' => 'entry-thumb', 'alt' => esc_attr( get_the_title() ) ) ); ?> <h2 class="entry-title"><?php echo wp_trim_words( get_the_title(), 8 ); ?></h2> <span class="icon-mark"><i class="fa fa-play"></i></span> </a> <?php endif; ?> </article> </li> <?php endforeach; ?> </ul> </div><!-- .jcarousel --> <?php if ( count( $video ) > 6 ) { ?> <a href="#" class="jcarousel-control-prev"><i class="fa fa-chevron-left"></i></a> <a href="#" class="jcarousel-control-next"><i class="fa fa-chevron-right"></i></a> <?php } ?> <?php endif; wp_reset_postdata(); ?> </div><!-- .container --> </div><!-- .carousel-loop --> <?php } ?> <div class="container"> <div class="row"> <div id="content-2" class="col-md-9 clearfix"> <main id="recent-content-2" class="content-loop"> <?php $latest2 = get_posts( array( 'posts_per_page' => 3, 'offset' => 3 ) ); ?> <?php if ( $latest2 ) : ?> <?php foreach ( $latest2 as $post ) : setup_postdata( $post ); ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <?php if ( has_post_thumbnail() ) : ?> <a class="hidden-xs" href="<?php the_permalink(); ?>" rel="bookmark"> <div class="entry-thumb-wrapper"> <?php the_post_thumbnail( 'gomedia-post-thumb', array( 'class' => 'entry-thumb', 'alt' => esc_attr( get_the_title() ) ) ); ?> <?php echo gomedia_get_post_format_icons(); // get the post format icons. ?> </div><!-- .entry-thumb-wrapper --> </a> <?php endif; ?> <header class="entry-header"> <?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?> <div class="entry-meta"> <?php gomedia_posted_on(); ?> </div><!-- .entry-meta --> </header><!-- .entry-header --> <div class="entry-excerpt"> <?php the_excerpt(); ?> </div><!-- .entry-excerpt --> </article><!-- #post-## --> <?php endforeach; ?> <?php gomedia_next_posts_link(); // Get the page/1/ link. ?> <?php endif; wp_reset_postdata(); ?> </main><!-- .site-main --> </div><!-- #content --> <?php get_sidebar( 'home-bottom' ); // Loads the sidebar-home-top.php templates. ?> </div><!-- .row --> </div><!-- .container --> <?php if ( of_get_option( 'gomedia_editor_picks', '1' ) ) { ?> <div id="carousel-2" class="carousel-loop"> <div class="container"> <h2 class="section-title"><?php _e( 'Editor\'s Picks', 'gomedia' ); ?></h2> <?php $editor_num = (int) of_get_option( 'gomedia_editor_picks_num', 10 ); ?> <?php $editor_tag = of_get_option( 'gomedia_editor_picks_tag' ); ?> <?php $picks = get_posts( array( 'posts_per_page' => $editor_num, 'tag_id' => $editor_tag ) ); ?> <?php if ( $editor_tag && $picks ) : ?> <div class="jcarousel jcarousel-carousel"> <ul> <?php foreach ( $picks as $post ) : setup_postdata( $post ); ?> <li> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <?php if ( has_post_thumbnail() ) : ?> <a href="<?php the_permalink(); ?>" rel="bookmark"> <?php the_post_thumbnail( 'gomedia-carousel-thumb', array( 'class' => 'entry-thumb', 'alt' => esc_attr( get_the_title() ) ) ); ?> <h2 class="entry-title"><?php echo wp_trim_words( get_the_title(), 8 ); ?></h2> <?php echo gomedia_get_post_format_icons(); // get the post format icons. ?> </a> <?php endif; ?> </article> </li> <?php endforeach; ?> </ul> </div><!-- .jcarousel --> <?php if ( count( $picks ) > 6 ) { ?> <a href="#" class="jcarousel-control-prev"><i class="fa fa-chevron-left"></i></a> <a href="#" class="jcarousel-control-next"><i class="fa fa-chevron-right"></i></a> <?php } ?> <?php endif; wp_reset_postdata(); ?> </div><!-- .container --> </div><!-- .carousel-loop --> <?php } ?> <?php get_footer(); ?> |
Như vậy là xong rồi đó. Chúc bạn thành công!
=>>> nguồn: https://thispc.vn/website/wordpress/tao-featured-section-2-cot-tren-theme-gomedia.html #thispc, #phanmem, #window, #mangmaytinh, #domainhosting, #taofeaturedsection2cottrenthemegomediathispc
- Nhận đường liên kết
- X
- Ứng dụng khác
Nhận xét
Đăng nhận xét