使用 WP 程序做門户 CMS 網站時,需要調用網站頭條新聞,讓第一個文章標題與其它的標題不一樣,以形成頭條的效果。如何使用 wp 網站代碼調用新聞頭條呢,下面就教新手學習怎麼做網站的學員們使用調用代碼。

代碼如下:

<?php if (have_posts()) : ?>
<?php query_posts('cat=6&showposts=7'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php if ($postcnt == 0) : ?>

<a href="<?php the_permalink() ?>"> <?php echo mb_strimwidth(get_the_title(), 0, 32, ''); ?></a>

<?php else : ?>

<a href="<?php the_permalink() ?>"> <?php the_title(); ?></a><br/>
<?php echo mb_strimwidth(strip_tags(get_the_content()),0,70," ");?><a rel="more-link" href="<?php the_permalink()?>" title="<?php the_title(); ?>">[閲讀詳情]</a>

<?php endif; $postcnt++; ?>
<?php endwhile; ?>

<?php endif; wp_reset_query();?>

 代碼解釋:

調用標題:<a href="<?php the_permalink() ?>"> <?php echo mb_strimwidth(get_the_title(), 0, 32, ''); ?></a>
調用標題:<a href="<?php the_permalink() ?>"> <?php the_title(); ?></a>
調用摘要:<?php echo mb_strimwidth(strip_tags(get_the_content()),0,70," ");?><a rel="more-link" href="<?php the_permalink()?>" title="<?php the_title(); ?>">[閲讀詳情]</a>