使用 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>