首页 文章

Wordpress如何显示第一个完整的帖子,然后其他人只是 Headers

提问于
浏览
0

我如何完整显示第一篇文章然后其他帖子只是 Headers .

我设法剥离了一些生成the_content的php代码,所以我可以显示 Headers . 现在我希望第一篇文章完全展示,除了其他人 .

谢谢 .

编辑:目前我有这个默认代码只是遍历每个帖子并显示 Headers .

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<div class="post-date"><?php the_time('F j, Y') ?></div>
<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>

2 回答

  • 1
    <?php $i=0; ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
     <?php $i+=1; ?>
     <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
     <div class="post-date"><?php the_time('F j, Y') ?></div> 
     <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
     <?php if($i<2): the_excerpt(); ?>
    ...
    
  • 0

    也许试试这个......

    <?php
    
        $per_page=$paged<=1?9:10;
    
        $i=0;
    
        query_posts(array(
    
            'order' => 'DESC',
    
            'paged' => $paged,
    
            'posts_per_page' => $per_page,
    
        ) );        
    
        if (have_posts()) :
    
        while (have_posts()) : the_post(); 
    
        if ($paged<=1 && $i==0)
    
    { ?>
    
        <!-- Loop that displays first post -->
    
        <div class="post-date"><?php the_time('F j, Y') ?></div>
        <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    
        <?php the_content()); ?>
    
    <?php } else { ?>
    
        <!-- Loop that displays rest of the post -->
    
        <div class="post-date"><?php the_time('F j, Y') ?></div>
        <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    
    
    <?php } $i++; endwhile; ?>
    
        <?php next_posts_link(__('&laquo; Older Entries')) ?>
        <?php previous_posts_link(__('Newer Entries &raquo;')) ?>
    
    <?php endif; wp_reset_query(); ?>
    

    顶部的数字是抵消它的数字 . $per_page=$paged<=1?9:10;

    第一页显示第一个循环 '1' 中的最新帖子,然后是其余 '9' ,然后在以下页面显示 '10' = <=1?9:10;

    希望这可以帮助 .

相关问题