wordpress 首页调用文章 不同样式的方法

时间:2023-01-04 06:16:42
<?php
  $count = 1;
  $display_categories = array(1);
  foreach ($display_categories as $category) { 
?>
            <?php query_posts("showposts=5&cat=$category")?>
            <?php while (have_posts()) :the_post(); ?>
            <?php if($count==1){ ?>
                <li class="news-first">
                    <div>
                    <span class="date pull-right"><?php the_time('Y-m-d') ?></span>
                    <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
                    </div>
                    <p class="news-excerpt"><?php echo mb_strimwidth(strip_tags(apply_filters('the_content',
$post->post_content)), 0, 200,"……"); ?></p>
                </li>
            <?php }else{ ?>
            <li class="news-item">
                <span class="date pull-right"><?php the_time('Y-m-d') ?></span>
                <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php echo
            mb_strimwidth(get_the_title(), 0, 40, '…'); ?></a>
            </li>  
            <?php } $count++;endwhile; ?>
            <?php } wp_reset_query();?>

 

在写wordpress主题时候遇到的小问题解决方法笔记