下前必看:!!!本站为会员制分享站,除商业源码分类外,其他源码恕不提供免费技术支持和咨询。 充值前,请先确认自己是否会技术。概不退款。
使用 wordpress 来调用当前最新文章内容是制作 wordrpess 主题时最常见的问题,一般都有在首页或者内页调用最新或是随机文章的嗜好,如果这些文章是同一个开源程序的,那比调用就相对容易一些。那以下给大家推荐了三种常用的 wordpress 文章调用方法,仅供大家参考。
WordPress 调用最新五篇文章
<?php query_posts('showposts=5'); ?>
<ul>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endwhile;?>
</ul>
其中的 showposts=5 为最新文章数量,可自定义数值。
WordPress 调用分类 ID 为 1 的分类下的五篇最新文章
<?php $rand_posts = get_posts('numberposts=5&category=1&orderby=date');foreach($rand_posts as $post) : ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach;?>
numberposts=5 五为文章数值的限定
category=1 1 为分类 ID 的限定
WordPress 调用最新文章
<?php $rand_posts = get_posts('numberposts=10&orderby=date');foreach($rand_posts as $post) : ?>
<li><a href="<?php the_permalink(); ?>"> <?php echo mb_strimwidth(get_the_title(), 0, 32, ''); ?></a></li>
<?php endforeach;?>
numberposts=10 最新 10 篇文章、orderby=date 按日期调用
以上三种方式分别通过最新的文章数量,最新的特定分类下的文章数量,最新的某时间内的文章数量来帮助大家更好的使用和了解 wordpress。