本文实例总结了wordpress随机调用显示文章的办法。分享给大家供大家参考。详细办法如下:
在wordpress中要随机显示文章这里给大家引见了三种调用随机文章的办法,有需求的冤家可依据本人的状况进行抉择.
办法一:采纳wordpress内置函数,在需求的时分间接调用以下代码:
<ul>
<?php $rand_posts = get_posts('numberposts=5&orderby=rand');
foreach( $rand_posts as $post ) : ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach; ?>
</ul><?php
query_posts('showposts=10&orderby=rand');
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
<li><em><?php echo $j++;?></em><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
endwhile; else:
?><?php
endif;
wp_reset_query();
?>function random_posts($posts_num=8,$before='<li>',$after='</li>'){
global $wpdb;
$sql = "SELECT ID, post_title,guid
FROM $wpdb->posts
WHERE post_status = 'publish' ";
$sql .= "AND post_title != '' ";
$sql .= "AND post_password ='' ";
$sql .= "AND post_type = 'post' ";
$sql .= "ORDER BY RAND() LIMIT 0 , $posts_num ";
$randposts = $wpdb->get_results($sql);
$output = '';
foreach ($randposts as $randpost) {
$post_title = stripslashes($randpost->post_title);
$permalink = get_permalink($randpost->ID);
$output .= $before.'<a href="'
. $permalink . '" rel="bookmark" title="';
$output .= $post_title . '">' . $post_title . '</a>';
$output .= $after;
}
echo $output;
}//random_posts()参数有$posts_num即文章数量,$before开端标签默许<li>,$after=完结标签默许</li><p class="right">
<h3>随意找点看看!</h3>
<ul>
<?php random_posts(); ?>
</ul>
</p>
心愿本文所述对大家的WordPress建站有所协助。
以上就是安达网络工作室关于《wordpress随机调用显示文章的方法总结》的一些看法。更多内容请查看本栏目更多内容!
很长工夫没有动过wordpress里的规划了,进过许久策动,明天决议扭转一下规划了。然而郁闷的事件随之而来,当...
本文实例讲述了WordPress完成网站投稿者也能够上传图片的办法。分享给大家供大家参考。详细剖析如下: Word...
自定义文章编辑器的款式 每一个 WordPress 主题的文章款式都是不一样的,然而在应用后盾的可视化编辑器编辑...
WordPress 现有的备份办法和存在的成绩 关于 WordPress 博客来说,有很多备份的办法,数据库能够间接经过 P...
招致wordpress页面呈现空白框的缘由大略有两点: 一,UTF-8即文件保留类型 文件保留类型与应用版本之间假如...
咱们在wordpress主题theme配置的时分,会从网站上下载比拟盛行的theme,使本人的blog看着很酷。也有不顺利的...