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随机文章/随机推荐的实现思路与用法》的一些看法。更多内容请查看本栏目更多内容!
comments-ajax.js在cdn缓存后,很多人遇到无奈(应用ajax)回复的成绩。对此,我之前的做法只是制止cdn缓存...
应用wordpass博客顺序的冤家都晓得他的默许首页是index.php,但是地球人都晓得index.html的太首页可以进步网...
通过两天的正则表白式的学习,和钻研wordpress的路由函数,胜利完成了自定义wordpress路由性能,以下是路由...
根本模板文件 style.css : CSS(款式表)文件index.php : 主页模板archive.php : Archive/Category模板404.ph...
【阐明】 反省以后文章能否置顶。前往值TRUE 或许 FALSE. 【用法】 复制代码代码如下:<?php is_sticky($pos...
对搜寻引擎暗藏特定的文章 这个成绩的起源是这样的: 家喻户晓,随着搜寻引擎的改进,会越来越排挤采集和伪...