1. WordPress如何让当前分类的文章列表按阅读量排列和热评数量排列
按阅读量排列,可安装插件 wp-postviews ,该插件提供了热门阅读文章列表调用代码: <?php if="" (function_exists('get_most_viewed')):="">?php> <?php get_most_viewed(); ?> <?php endif; ?> 或者 <?php if(function_exists('the_views'))="" {="" the_views();="" }="" ?=""> 或者 //显示最热门文章<?php get_most_viewed($mode='' ,="" $limit="10," $chars="0," $display="true)" ?="">//显示某个或某些目录下最冷门文<?php get_least_viewed_category($category_id="0," $mode='' ,="" $limit="10," $chars="0," $display="true)" ?="">//显示某个或某些目录下最热门文章<?php get_most_viewed_category($category_id="0," $mode='' ,="" $limit="10," $chars="0," $display="true)" ?="">//显示指定标签下的最热门文章<?php get_most_viewed_tag($tag_id="0," $mode='' ,="" $limit="10," $chars="0," $display="true)" ?="">//显示指定标签下的最冷门文章<?php get_least_viewed_tag($tag_id="0," $mode='' ,="" $limit="10," $chars="0," $display="true)" ?="">//显示全站文章总共被浏览过多少次<?php get_totalviews();="" ?=""> 特定时间内阅读量: ### Function: Get TimeSpan Most Viewedfunction get_timespan_most_viewed($mode = '', $limit = 20, $days = 30, $display = true) {global $wpdb, $post;$limit_date = current_time('timestamp') - ($days*86400);$limit_date = date("Y-m-d H:i:s",$limit_date);$where = '';$temp = '';if(!empty($mode) && $mode != 'both') {$where = "post_type = '$mode'";} else {$where = '1=1';}$most_viewed = $wpdb->get_results("SELECT DISTINCT $wpdb->posts.*, (meta_value+0) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."'="" and="" post_date=""> '".$limit_date."' AND $where AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER BY views DESC LIMIT $limit");if($most_viewed) {foreach ($most_viewed as $post) {$post_title = get_the_title();$post_views = intval($post->views);$post_views = number_format($post_views);$temp .= "$post_title - $post_views ".__('views', 'wp-postviews')."";}} else {$temp = ''.__('N/A', 'wp-postviews').''."\n";}if($display) {echo $temp;} else {return $temp;}} $days这个参数是多长时间内发表的文章,设置为30,就是1个月的热门文章。
2. wordpress如何从指定分类里获取文章到另一个分类
我建议你在当前皮肤下新建个category-hot.php文件这样就不需要再去判断了,当用户点击热门分类时,自动会调用category-hot.php这个模板文件另外,建议你用WP_Query这个类来重新查询结果,如: <?php$args =="" array(="" 'category__in'=""> 8, 'posts_per_page' => 10);$hots = new WP_Query($args);if ( $hots -> have_posts() ) while( $hots -> have_posts() ) : $hots -> the_post(); 。
endwhile;endif;?>。
3. wordpress怎么实现不同分类目录页面显示文章数量不同
这个问题,主要是判断你当前分类的ID,然后按照你的意愿 ,向pre_get_posts添加自定义函数就可以了。
例如:
if ( is_category() {
$cid = get_queried_object_id();
if ( $cid == '新闻分类ID' ){
$posts_per_page = 20
}
if ( $cid == '相册分类ID' ){
$posts_per_page = 10
}
add_action('pre_get_posts', 'custom_posts_per_page');
function custom_posts_per_page( $query ) {
$query->set( 'posts_per_page', $posts_per_page );
return;
}
}
4. wordpress 获取本类下浏览次数最多的文章
如你所要求的,本月/本周 浏览次数最多的6篇文章,最好使用的Wordpress Popular Posts插件。
WP-POSTVIEWS茂似也可以,但修改插件或代码,新版本的WP-PostViews不带某个函数调用了,还挺麻烦的,而且效果没Wordpress Popular Posts好,所以建议用Wordpress Popular Posts插件来调用是最好!为啥那么说,因为Wordpress Popular Posts插件也可以显示文章浏览次数。它不仅可以本月/本周浏览次数最多的某几篇文章,而且可以当天或者所有时间里的浏览次数最多的文章,或按评论次数来显示。
可以看u142.com/author/xiaofan这个页面,就是利用这个插件做的。我贴出来那部分调用的代码,具体如何调用,插件后台有写说明的。
作者热门文章排行榜 本周 本月 经典 $ppargs=array( 'range' => 'weekly', 'order_by' => 'views', 'post_type' => 'post', 'author' => $current_author_id, 'stats_comments' => 0, 'stats_views' => 1, 'wpp_start' => '', 'wpp_end' => '', 'post_start' => '1. ', 'post_end' => '', ); wpp_get_mostpopular($ppargs); } ?> $ppargs=array( 'range' => 'monthly', 'order_by' => 'views', 'post_type' => 'post', 'author' => $current_author_id, 'stats_comments' => 0, 'stats_views' => 1, 'wpp_start' => '', 'wpp_end' => '', 'post_start' => '1. ', 'post_end' => '', ); wpp_get_mostpopular($ppargs); } ?> $ppargs=array( 'range' => 'all', 'order_by' => 'views', 'post_type' => 'post', 'author' => $current_author_id, 'stats_comments' => 0, 'stats_views' => 1, 'wpp_start' => '', 'wpp_end' => '', 'post_start' => '1. ', 'post_end' => '', ); wpp_get_mostpopular($ppargs); } ?> 以上个人观点,仅供参考。
5. wordpress如何获得当前自定义分类的id
当前页是分类页 系统默认有个变量$cat,就是当前分类的ID 当前页是单页 第一种方法 $cat= single_cat_title('', false);echo get_cat_ID($cat); 第二种方法 if (!is_page() && !is_home()){ $catsy = get_the_category(); $myCat = $catsy[0]->cat_ID; $currentcategory = '¤t_category='.$myCat;}wp_list_categories('hierarchical=1&use_desc_for_title=0&exclude=12&depth=1&orderby=id&title_li='.$currentcategory); 第三种方法 foreach((get_the_category()) as $category) { echo $category->cat_ID . ''; //当前文章的分类的ID echo $category->cat_name . ''; //当前文章的分类的名称}。
6. 黄聪:如何WP中获取文章分类名称、分类ID、归档分类链接
the category 一般用在文章页,显示当前文章的分类链接:括号内可填写内容如:',',表示当前文章属于多个分类时,以逗号间隔,也可以设置为其他间隔方式;single_cat_title 标签用在归档页,分类归档页显示分类名,标签归档页显示标签名,都是纯文本,非锚链接:wp_list_categories该标签用得很多,功能很复杂,参数比较多,但是用它显示某一分类也可以,不过是锚链接:等号后面需要填某一分类的id(id可以在后台鼠标移动到某一链接时,状态栏会显示出来);get_the_category 1、不大常见,但用处挺大,一般用法: 1、不大常见,但用处挺大,一般用法:cat_name;}?>2、其他用法: 评论0 0 0。
7. wordpress如何获得当前自定义分类的id
当前页是分类页
系统默认有个变量$cat,就是当前分类的ID
当前页是单页
第一种方法
$cat= single_cat_title('', false);
echo get_cat_ID($cat); 第二种方法
if (!is_page() && !is_home()){
$catsy = get_the_category(); $myCat = $catsy[0]->cat_ID; $currentcategory = '¤t_category='.$myCat;
}
wp_list_categories('hierarchical=1&use_desc_for_title=0&exclude=12&depth=1&orderby=id&title_li='.$currentcategory); 第三种方法
foreach((get_the_category()) as $category) {
echo $category->cat_ID . ''; //当前文章的分类的ID
echo $category->cat_name . ''; //当前文章的分类的名称
}
8. wordpress 如何获取循环对应的文章分类name和slug
参考以下代码:
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post();
$categories = get_the_category();//获取当前post的分类信息
if ( empty( $categories ) ) {
echo "Uncategorized";
} else {
foreach ($categories as $category ) {
//循环输出分类的name与slug
echo $category->name . ":" . $cateogry->slug;
}
}
endwhile; ?>
<?php else : ?>
<?php endif; ?>
转载请注明出处51数据库 » wordpress获取当前分类文章数
?php$args>?php>?php>?php>?php>?php>?php>?php>
花落季16238097