WordPress企业主题定制/开发/优化

无插件调用WordPress随机文章、最新文章、最热文章

首页 » WORDPRESS教程 » 无插件调用WordPress随机文章、最新文章、最热文章

不用插件调用WordPress随机文章、最新文章、和30天内最热文章。

今天介绍的是不用插件调用WordPress随机文章、最新文章和30天内最热的文章。

随机文章对于SEO而言是非常有用的,就算你的网站长时间不更新,快照也会经常更新不会停歇。所以说调用随机文章是非常有必要的,一般调用在边栏比较好。具体方法如下:

不用插件调用WordPress随机文章

<ul><li><h3><?php _e('随机推荐'); ?></h3><ul><?php $rand_posts = get_posts('numberposts=6&orderby=rand');  foreach( $rand_posts as $post ) : ?><li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php echo mb_strimwidth(get_the_title(), 0, 42, '...'); ?></a></li><?php endforeach; ?></ul></ul>

不用插件调用WordPress最新文章

<ul><li><h3><?php _e('最新文章'); ?></h3><?php query_posts("showposts=6&caller_get_posts=1&orderby=date&order=DESC"); ?><ul><?php if (have_posts()) : while (have_posts()) : the_post(); ?><li><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php echo mb_strimwidth(get_the_title(), 0, 42, '...'); ?></a></li><?php endwhile; endif; ?></ul></li>

不用插件调用WordPress30内最热文章

<li><h3><?php _e('最热文章'); ?></h3><?php  function filter_where($where = '') { //posts in the last 30 days $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'"; return $where;  } add_filter('posts_where', 'filter_where'); query_posts("showposts=8&v_sortby=views&caller_get_posts=1&orderby=date&order=desc") ?><ul><?php if (have_posts()) : while (have_posts()) : the_post(); ?><li><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php echo mb_strimwidth(get_the_title(), 0, 42, '...'); ?> </a></li><?php endwhile; endif; ?><?php wp_reset_query(); ?></ul></li>

其中<?php echo mb_strimwidth(get_the_title(), 0, 42, '...'); ?> 使用的是 控制

相关项目

  • WordPress外贸企业主题

  • 最近更新

  • 热门标签