wordpress怎么获取最新文章与时间
如你所要求的,本月/本周 浏览次数最多的6篇文章,最好使用的Wordpress Popular Posts插件。
WP-POSTVIEWS茂似也可以,但修改插件或代码,新版本的WP-PostViews不带某个函数调用了,还挺麻烦的,而且效果没Wordpress Popular Posts好,所以建议用Wordpress Popular Posts插件来调用是最好!为啥那么说,因为Wordpress Popular Posts插件也可以显示文章浏览次数。
它不仅可以本月/本周浏览次数最多的某几篇文章,而且可以当天或者所有时间里的浏览次数最多的文章,或按评论次数来显示。
可以看u142.com/author/xiaofan这个页面,就是利用这个插件做的。
我贴出来那部分调用的代码,具体如何调用,插件后台有写说明的。
作者热门文章排行榜本周本月 经典'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);}?>'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);}?>'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);}?>以上个人观点,仅供参考
wordpress添加新页面后不显示评论!
WordPress本身自带一个函数可以调出分类别名和链接:但在实际的应用中,我们可能需要单独调出 wordpress 的分类,并不需要添加链接,那该如何只调出文章分类的名称呢?如果是在分类页面进行调用:如果是在文章页面进行所属分类名称的调用:cat_name;}>如何调出分类别名呢?if(is_category()) {$cat = get_query_var('cat');$yourcat = get_category($cat);echo "该分类别名为" . $yourcat->slug;}
wordpress如何获取当前文章的id,要求写一个函数在function里面调用 ...
//The args$args = array('cat' =>61 //这是分类ID,也可以用array给一组ID);// The Result$naruco= new WP_Query( $args );if ( $naruco->have_posts() ) {// The Loopwhile ( $naruco->have_posts() ) : $naruco->the_post();echo '';$post_ID = get_the_ID(); //这就是文章的ID了。
$post_content = get_the_content(); //文章内容,至于怎么截取一定长度的字数,百度一下到处都是啦。
echo '';endwhile;}else {echo 'no posts in current category!';}?>说的全在注释里了。
怎么去掉wordpress主页文章下面的浏览跟评论标志。
一、使用 WordPress 内置函数 get_posts() $posts = get_posts( 'numberposts=-1&category=3' );echo count($posts);?>二、使用 WordPress 内置函数 get_category_by_slug()// 将以下'category-name'改成你的分类别名即可echo get_category_by_slug('category-name')->count;?>三、使用 WordPress 内置函数 get_category()// 将以下 cat_ID 改成你的分类 ID 即可echo get_category(cat_ID)->count;?>四、使用 WordPress 的内置函数 wp_list_categories()参数 include 的等号后面 3 改成你想要统计文章数的分类 ID 即可。
最终输出形式为:分类名称(文章数) ,如图像印记(20)五、使用 wpdb 直接查询数据库将以下 PHP 代码放置在主题目录下的 functions.php 中function wt_get_category_count($input = '') {global $wpdb;if($input == '') {$category = get_the_category();return $category[0]->category_count;}elseif(is_numeric($input)) {$SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->term_taxonomy.term_id=$input";return $wpdb->get_var($SQL);}else {$SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->terms.slug='$input'";return $wpdb->get_var($SQL);}}然后在需要的地方调用该函数即可,该函数提供三种调用方式:1、在主循环中调出该函数,且不提供参数,则返回第一个分类的文章数:2、提供的参数为数字,且该数字为分类的 ID 号,则返回对应 ID 的分类的文章数:3、提供分类的别名,则返回对应缩略名(别名)的分类文章数:该函数对于含有子分类的分类,文章数统计上会有稍许误差。
对于分类文章数为 0 的情况统计得也不是很好。
转载请注明出处51数据库 » wordpress 获取文章评论
饼大不过烙它的锅34341574