seo中随机文章有什么特别重要的地方有什么用

阅读  ·  发布日期 2018-10-02 08:45  ·  admin
一般WordPress博客默认小工具可以添加近期文章列表,可近期文章本来就在首页有大面积展示,在右侧边栏显示略显浪费首页位置,故灬无言建议右侧添加随机文章列表。
 
 
今天,慕枫宁波seo小编为大家介绍随机文章的作用是什么以及如何为WordPress添加随机文章小工具。希望对大家有所帮助。
 
 
 
 
一、随机文章的作用
 
 
1、充分收录文章
 
 
网站首页的随机文章可以让搜索引擎将网站文章收录的更彻底,因为一般情况下搜索引擎蜘蛛光临首页的次数是最多的。这样蜘蛛可以去爬行那些被随机展示出来的且未被收录的文章,让网站文章收录更充分。
 
 
2、提升快照更新频率
 
 
如果我们的网站在一段时间内不更新,也就是说首页几个月都是同样的,没有一丝变化,相信快照更新的时间会很长。可如果我们增加了随机文章列表,让首页保持着变化,会缩短快照更新的时间。
 
 
3、用户的驻留时间增长
 
 
用户在看到随机文章列表时,很有可能以往的文章更能吸引他的目光,从而完成一次新的点击,PV的提升,驻留时间自然会增长。
 
宁波seo
 
二、如何为WordPress添加随机文章小工具
 
 
可以由插件实现,也可以通过后台添加代码来实现。这里小小课堂网仅介绍代码实现,因为解决问题的方式更直接。
 
 
在主题目录下找到并修改functions.php文件。
 
 
一般在wp-content > themes文件夹下,打开之后,在结尾处添加如下代码。
 
//随机文章小工具
 
class RandomPostWidget extends WP_Widget
 
{
 
function RandomPostWidget()
 
{
 
parent::WP_Widget('bd_random_post_widget', '随机文章', array('deion'=> '我的随机文章小工具') );
 
}
 
function widget($args, $instance)
 
{
 
extract( $args );
 
$title=apply_filters('widget_title',empty($instance['title']) ? '随机文章' :
 
$instance['title'], $instance, $this->id_base);
 
if ( empty( $instance['number'] ) || ! $number=absint( $instance['number'] ) )
 
{
 
$number=10;
 
}
 
$r=new WP_Query(array('posts_per_page'=> $number, 'no_found_rows'=> true,
 
'post_status'=> 'publish', 'ignore_sticky_posts'=> true, 'orderby'=>'rand'));
 
if ($r->have_posts())
 
{
 
echo " ";
 
echo $before_widget;
 
if ( $title ) echo $before_title . $title . $after_title;
 
?>
 
 
 
have_posts()) : $r->the_post(); ?>
 
 
 
 
echo $after_widget;
 
wp_reset_postdata();
 
}
 
}
 
function update($new_instance, $old_instance)
 
{
 
$instance=$old_instance;
 
$instance['title']=strip_tags($new_instance['title']);
 
$instance['number']=(int) $new_instance['number'];
 
return $instance;
 
}
 
function form($instance)
 
{
 
$title=isset($instance['title']) ? esc_attr($instance['title']) : '';
 
$number=isset($instance['number']) ? absint($instance['number']) : 10;?>
 
 
 
 
<?php echo $title; ?>
 
 
 
 
show:'); ?>
 
 
<?php echo $number; ?>
 
 
}
 
}
 
add_action('widgets_init', create_function('', 'return register_widget("RandomPostWidget");'));
 
?>
 
在小工具这里就可以看到我们新添加的“随机文章”啦。
 
宁波seo
 
以上就是慕枫宁波seo小编为大家带来的随机文章的作用以及为WordPress小工具添加随机文章。感谢您的观看。