本日,小小教室网为大家先容随机文章的浸染是什么以及如何为WordPress添加随机文章小工具。希望对大家有所帮助。
一、随机文章的浸染
1、充分收录文章
网站首页的随机文章可以让搜索引擎将网站文章收录的更彻底,由于一样平常情形下搜索引擎蜘蛛光临首页的次数是最多的。这样蜘蛛可以去爬行那些被随机展示出来的且未被收录的文章,让网站文章收录更充分。如何让百度快速收录,参考以往教程《如何让百度快速收录网站及文章?_小小教室网》

2、提升快照更新频率
如果我们的网站在一段韶光内不更新,也便是说首页几个月都是同样的,没有一丝变革,相信快照更新的韶光会很长。可如果我们增加了随机文章列表,让首页保持着变革,会缩短快照更新的韶光。什么是百度快照,参考以往教程《什么是百度快照?对SEO优化有用吗?》
3、用户的驻留韶光增长
用户在看到随机文章列表时,很有可能以往的文章更能吸引他的目光,从而完成一次新的点击,PV的提升,驻留韶光自然会增长。
二、如何为WordPress添加随机文章小工具可以由插件实现,也可以通过后台添加代码来实现。这里小小教室网仅先容代码实现,由于办理问题的办法更直接。
在主题目录下找到并修正functions.php文件。
一样平常在wp-content > themes文件夹下,打开之后,在结尾处添加如下代码。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//随机文章小工具
class RandomPostWidget extends WP_Widget
{
function RandomPostWidget()
{
parent::WP_Widget('bd_random_post_widget', '随机文章', array('description' => '我的随机文章小工具') );
}
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 \"大众\n\公众;
echo $before_widget;
if ( $title ) echo $before_title . $title . $after_title;
?>
<ul class=\"大众line\公众>
<?php while ($r->have_posts()) : $r->the_post(); ?>
<li><a href=\"大众<?php the_permalink() ?>\"大众 title=\公众<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>\"大众><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
<?php endwhile; ?>
</ul><?php
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;?>
<p><label for=\"大众<?php echo $this->get_field_id('title'); ?>\公众><?php _e('Title:'); ?></label>
<input id=\公众<?php echo $this->get_field_id('title'); ?>\"大众 name=\"大众<?php echo $this->get_field_name('title'); ?>\公众 type=\"大众text\公众 value=\公众<?php echo $title; ?>\"大众 /></p>
<p><label for=\"大众<?php echo $this->get_field_id('number'); ?>\公众><?php _e('Number of posts to
show:'); ?></label>
<input id=\公众<?php echo $this->get_field_id('number'); ?>\"大众 name=\公众<?php echo $this->get_field_name('number'); ?>\"大众 type=\"大众text\"大众 value=\"大众<?php echo $number; ?>\公众 size=\"大众3\公众 /></p>
<?php
}
}
add_action('widgets_init', create_function('', 'return register_widget(\公众RandomPostWidget\公众);'));
?>
在小工具这里就可以看到我们新添加的“随机文章”啦。
以上便是小小教室网为大家带来的随机文章的浸染以及为WordPress小工具添加随机文章。感谢您的不雅观看。
喜好记得,点赞,打赏哦。小小教室,每天一个IT原创视频和图文教程,别忘了关注哦。