رفتن به مطلب

مطالب محبوب دسته جاری


پست های پیشنهاد شده

سلام چجوری میشه مطالب محبوب دسته جاری (یعنی دسته ای که باز شده) رو نشون داد 

واسه مطالب محبوب از این کد در فانکشن استفاده می کنم

function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0 بازدید";
}
return $count.' بازدید';
}
function setPostViews($postID) {
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
}else{
$count++;
update_post_meta($postID, $count_key, $count);
}
}
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);

و برای نمایش محبوبترین مطالب از این کد

  <?php $popularpost = new WP_Query( array( 'posts_per_page' => 4, meta_key => post_views_count’, orderby => meta_value_num’, order => DESC ) );
while ( $popularpost->have_posts() ) : $popularpost->the_post();
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>

فیلتر دسته جاری بهش اضافه کنید فقط

ویرایش شده توسط omidghs
لینک به ارسال
  • 3 هفته بعد...

ای دی دسته جاری رو باید بگیرید و به کوئری اضافه کنید. روشهای این کار:

 

$categories = get_the_category();
$category_id = $categories[0]->cat_ID;

یا

$category = get_category( get_query_var( 'cat' ) );
$cat_id = $category->cat_ID;

یا

$cat_obj = $wp_query->get_queried_object();
$thiscat_id = $cat_obj->term_id;
$thiscat = get_category($thiscat_id);
$parentcat = get_category($thiscat->parent);

یا

$wp_query->query_vars['cat']

 

لینک به ارسال

لطفا برای ارسال دیدگاه وارد شوید

شما بعد از اینکه وارد حساب کاربری خود شدید می توانید دیدگاهی ارسال کنید



ورود به حساب کاربری
×
×
  • اضافه کردن...