在自己做網站時,網站首頁需要調用網站中最新發布的文章,如何讓網站自動的調用出網站後台的文章呢,就需要添加 WordPress 最新文章。 WordPress 調用最新文章的代碼有三種,通過以下三種代碼都可以調用出網站中的最新文章。學做網站的學員們可以根據自己的需要在自己的網站上添加任一代碼。
第一種調用 WordPress 最新文章代碼
<?php wp_get_archives('type=postbypost&limit=10'); ?>
第二種調用 WordPress 最新文章代碼
<ul>
<?php
$cats = wp_get_post_categories($post->ID);
if ($cats) {
$args = array(
'category__in' => array( $cats[0] ),
'post__not_in' => array( $post->ID ),
'showposts' => 5,
'caller_get_posts' => 1
);
query_posts($args);
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<li><?php include( TEMPLATEPATH . '/thumbnail.php' ); ?><p><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"> <?php the_title() ?></a></p></li>
<?php endwhile; else : ?>
<?php endif; wp_reset_query(); } ?>
</ul>
第三種調用 WordPress 最新文章代碼
<ul>
<?php $post_query = new WP_Query(『showposts=10′);
while ($post_query->have_posts()) : $post_query->the_post();
$do_not_duplicate = $post->ID; ?>
<li><a href=」<?php the_permalink(); ?>」><?php the_title(); ?></a></li>
<?php endwhile;?>
</ul>
第四種調用 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 按日期調用