wordpress完成随机文章
ralix曾公布过对于wordpress随机文章的相干插件的点评文章(“wordpress插件之随机文章类插件点评”),百度一下也能搜出很多其余纯代码的形式,大抵代码如下:
<?php
$query = array(
'post_type' => 'post',
'orderby' => 'rand'
);
$posts = new WP_Query( $query );
if ( $posts->have_posts() ) {
while( $posts->have_posts() ) :
$posts->the_post();
the_content();
endwhile;
}
wp_reset_query();
?>
<?php
//获取置顶文章的ID串
$rand_id = get_option( 'sticky_posts' );
$query = array(
'post__in' => $rand_id,
'post_type' => 'post',
'orderyby' => 'rand',
'numberposts' => 2
);
$posts = new WP_Query( $query );
if ( $posts->have_posts() ) {
while( $posts->have_posts() ) :
$posts->the_post();
the_content();
endwhile;
}
wp_reset_query();
?>
<?php
add_action('init','random_add_rewrite');
add_action('template_redirect','random_template');
function random_add_rewrite() {
global $wp;
$wp->add_query_var('random');
add_rewrite_rule('random/?$', 'index.php?random=1', 'top');
}
function random_template() {
if (get_query_var('random') == 1) {
$posts = get_posts('post_type=post&orderby=rand&numberposts=1');
foreach($posts as $post) {
$random_link = get_permalink($post);
}
wp_redirect($random_link,307); //307暂时跳转
exit;
}
}
?>
以上就是安达网络工作室关于《wordpress随机文章/随机推荐的实现思路与用法》的一些看法。更多内容请查看本栏目更多内容!
关于日拜访量还不错的WordPress网站来说,一定都会存在很多待审核的渣滓评论,假如要经过WP后盾删除,那几乎...
WordPress显示文章题目的时分,当文章题目过长而且文章的题目又在主页显示时,假如发作换行的景象就显得不美...
1. 自定义用户名和明码 新版本一开端就会给用户惊喜! 目前咱们装置WordPress之后,零碎会给咱们一个用户ad...
其实我集体并不是很喜爱这种摘要的显示形式,然而这个办法用起来比拟不便而已。 WordPress是有摘要性能...
wordpress不同分类调用不同模板文件 用wordpress做站特地是企业站的时分,多个分类的内容不同需求显示的页面...
代码如下:<?php/*在根目录 -> wp-content -> themes 下创立mytheme文件夹用来寄存创立新主题模板 在mythem...