omidghs 3 ارسال شده در آذر 95 گزارش بازنشر ارسال شده در آذر 95 (ویرایش شده) سلام چجوری میشه مطالب محبوب دسته جاری (یعنی دسته ای که باز شده) رو نشون داد واسه مطالب محبوب از این کد در فانکشن استفاده می کنم 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; ?> فیلتر دسته جاری بهش اضافه کنید فقط ویرایش شده آذر 95 توسط omidghs نقل قول لینک به ارسال
Morteza 34190 ارسال شده در آذر 95 گزارش بازنشر ارسال شده در آذر 95 ای دی دسته جاری رو باید بگیرید و به کوئری اضافه کنید. روشهای این کار: $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'] نقل قول لینک به ارسال
پست های پیشنهاد شده
به گفتگو بپیوندید
هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .