您现在的位置是:首页 > 网站制作 > WordpressWordpress

WordPress调用最新文章 热门文章 相关文章 随机文章代码

杰帅2023-07-20【Wordpress】人已围观

简介wordpress程序是一个比较高效的网站制作程序,在学员学习如何做网站的时候,可以使用wp程序作为自己的首选建站程序,只要熟练的运用它的网站代码就可以制作出自己需要的网站来。

wordpress程序是一个比较高效的网站制作程序,在学员学习如何做网站的时候,可以使用wp程序作为自己的首选建站程序,只要熟练的运用它的网站代码就可以制作出自己需要的网站来。

下面是学做网站论坛提供关于wordpress程序调用最新文章、热门文章、相关文章、随机文章代码,供广大学习网站制作培训课程的学员共享。

wordpress最新文章代码:

<?php query_posts('&caller_get_posts=1&showposts=10'); while (have_posts()) : the_post(); ?>
<li><a href='<?php the_permalink(); ?>'> <?php the_title(); ?></a></li>
<?php endwhile;wp_reset_query(); ?>

numberposts=10最新10篇文章
orderby=date按日期调用

wordpress相关文章代码:(调用同一分类)

<?php
$cats = wp_get_post_categories($post->ID);
if ($cats) {
$args = array(
'category__in' => array( $cats[0] ),
'post__not_in' => array( $post->ID ),
'showposts' => 6,
'caller_get_posts' => 1
);
query_posts($args);
if (have_posts()) :
while (have_posts()) : the_post(); update_post_caches($posts); ?>
<li><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; else : ?>
<li> 暂无相关文章</li>
<?php endif; wp_reset_query(); } ?>

标签相关文章调用:(调用相同标签下的文章)

<?php
global $post;
$post_tags = wp_get_post_tags($post->ID);
if ($post_tags) {
foreach ($post_tags as $tag) {
// 获取标签列表
$tag_list[] .= $tag->term_id;
}

// 随机获取标签列表中的一个标签
$post_tag = $tag_list[ mt_rand(0, count($tag_list) - 1) ];

// 该方法使用 query_posts() 函数来调用相关文章,以下是参数列表
$args = array(
'tag__in' => array($post_tag),
'category__not_in' => array(NULL), // 不包括的分类ID
'post__not_in' => array($post->ID),
'showposts' => 10, // 显示相关文章数量
'caller_get_posts' => 1
);
query_posts($args);

if (have_posts()) {
while (have_posts()) {
the_post(); update_post_caches($posts); ?>
<li>* <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php
}
}
else {
echo '<li>* 暂无相关文章</li>';
}
wp_reset_query();
}
else {
echo '<li>* 暂无相关文章</li>';
}
?>

wordpress随机文章代码:

<?php $rand_posts = get_posts('numberposts=10& category=1&orderby=rand');foreach($rand_posts as $post) : ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach;?>

numberposts=10 最新10篇文章
orderby=date 按日期调用
category=1 只调用某个分类目录下的文章

Tags:wordpress教程   最新文章   热门文章   相关文章

很赞哦! ()

文章评论

本站推荐

站点信息

  • 建站时间:2018-10-24
  • 网站程序:帝国CMS7.5
  • 主题模板《今夕何夕》
  • 文章统计1172篇文章
  • 标签管理标签云
  • 统计数据百度统计
  • 微信公众号:扫描二维码,关注我们