在自己做網站時,網站首頁需要呼叫網站中最新發布的文章,如何讓網站自動的呼叫出網站後臺的文章呢,就需要新增 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 按日期呼叫