* Code hiển thị bài viết liên quan trong cùng 1 category
$cate = get_the_category(get_the_ID());
foreach( $cate as $individual_category ) $cate_id[] = $individual_category->term_id;
'category__in' => $cate_id,
'post__not_in' => array(get_the_ID()),
$query = new wp_query($args);
if( $query->have_posts() ):
while ($query->have_posts()): $query->the_post(); ?>
<div class="col-sm-6 col-md-4 margin-top wow bounceInLeft">
<div class="alert alert-success alert-dismissible fade show" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
<strong><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></strong>
<?php endwhile; endif; wp_reset_query(); ?>
<?php
/*
* Code hiển thị bài viết liên quan trong cùng 1 category
* Code by ibegins.net
*/
$cate = get_the_category(get_the_ID());
if ($cate){
$cate_id = array();
foreach( $cate as $individual_category ) $cate_id[] = $individual_category->term_id;
$args = array(
'category__in' => $cate_id,
'post__not_in' => array(get_the_ID()),
'posts_per_page' => 6,
);
$query = new wp_query($args);
if( $query->have_posts() ):
while ($query->have_posts()): $query->the_post(); ?>
<div class="col-sm-6 col-md-4 margin-top wow bounceInLeft">
<div class="alert alert-success alert-dismissible fade show" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<strong><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></strong>
</div>
</div>
<?php endwhile; endif; wp_reset_query(); ?>
<?php } ?>
<?php
/*
* Code hiển thị bài viết liên quan trong cùng 1 category
* Code by ibegins.net
*/
$cate = get_the_category(get_the_ID());
if ($cate){
$cate_id = array();
foreach( $cate as $individual_category ) $cate_id[] = $individual_category->term_id;
$args = array(
'category__in' => $cate_id,
'post__not_in' => array(get_the_ID()),
'posts_per_page' => 6,
);
$query = new wp_query($args);
if( $query->have_posts() ):
while ($query->have_posts()): $query->the_post(); ?>
<div class="col-sm-6 col-md-4 margin-top wow bounceInLeft">
<div class="alert alert-success alert-dismissible fade show" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<strong><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></strong>
</div>
</div>
<?php endwhile; endif; wp_reset_query(); ?>
<?php } ?>
Gán code sau vào single.php hoặc sidebar.php
Nếu gắn vào sidebar.php thêm đoạn sau bọc code trên vào :
<?php if( is_single() ) : ?>
<?php if( is_single() ) : ?>
--- Code trên --
<?php endif; ?>
<?php if( is_single() ) : ?>
--- Code trên --
<?php endif; ?>
Ngày 5 Tháng Ba, 2018 ( 915 )
Tagged with: bài cùng chuyên mục, code cùng chuyên mục, share code wordpress
Bình luận bài viết
Đăng nhập để bình luận và xem các bình luận khác.