WordPress 程序是一個比較高效的網站製作程序,在學員學習如何做網站的時候,可以使用 wp 程序作為自己的首選建站程序,只要熟練的運用它的網站代碼就可以製作出自己需要的網站來。

下面是學做網站提供關於 WordPress 程序調用最新文章、熱門文章、相關文章、隨機文章代碼,供廣大學做網站學員共享。

WordPress 最新文章代碼:

<?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;?>

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 相關文章代碼:

<?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="http://<?php%20the_permalink();%20?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; else : ?>
<li> 暫無相關文章</li>
<?php endif; wp_reset_query(); } ?>
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 只調用某個分類目錄下的文章