有时候,我们在wordpress修改过程中,会用到按周浏览或者按月浏览的情况,尤其是需要做一些热门浏览的单页,要根据浏览次数获取本周或本月热门文章怎么调用等等,直接上代码,具体根据自己实际情况来修改使用,因为代码并不一定百分百适应全部主题要修改查询字段。
wordpress获取一周热门文章排行
<?php
function mostweek($where = '') {
//获取最近七天的文章
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-7 days')) . "'";
return $where;
}
add_filter('posts_where', 'mostweek'); ?>
<?php query_posts("v_sortby=views&caller_get_posts=1&orderby=date&v_orderby=desc&showposts=10") ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
>li>>a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?>>/a>>/li>
<?php endwhile; ?>
<?php endif; ?>
wordpress获取一月热门文章排行
<?php
function mostmonth($where = '') {
//获取最近30天文章
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
return $where;
}
add_filter('posts_where', 'mostmonth'); ?>
<?php query_posts("v_sortby=views&caller_get_posts=1&orderby=date&v_orderby=desc&showposts=10") ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></li>
<?php endwhile; ?>
<?php endif;
?>
根据评论数获取热门
<h2>热门文章</h2>
<ul id="popular-posts">
<?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 6");
foreach ($result as $post) {
setup_postdata($post);
$postid = $post->ID;
$title = $post->post_title;
$commentcount = $post->comment_count;
if ($commentcount != 0) { ?>
<li><a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>">
<?php echo $title ?></a> {<?php echo $commentcount ?> 个评论}</li>
<?php } } ?>
</ul>
wordpress获取一周热门文章排行
<?php
function mostweek($where = '') {
//获取最近七天的文章
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-7 days')) . "'";
return $where;
}
add_filter('posts_where', 'mostweek'); ?>
<?php query_posts("v_sortby=views&caller_get_posts=1&orderby=date&v_orderby=desc&showposts=10") ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></li>
<?php endwhile; ?>
<?php endif; ?>
wordpress获取一月热门文章排行
<?php
function mostmonth($where = '') {
//获取最近30天文章
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
return $where;
}
add_filter('posts_where', 'mostmonth'); ?>
<?php query_posts("v_sortby=views&caller_get_posts=1&orderby=date&v_orderby=desc&showposts=10") ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></li>
<?php endwhile; ?>
<?php endif; ?>
© 版权声明
THE END
暂无评论内容