【问题标题】:Wordpress How to show first full post then others are titles onlyWordpress 如何显示第一个完整的帖子,然后其他的只是标题
【发布时间】:2011-12-05 14:12:04
【问题描述】:

我如何完整显示第一个帖子,然后其他帖子只显示标题。

我已经设法剥离了一些生成 the_content 的 php 代码,这样我就可以只显示标题了。现在我希望第一个帖子完整显示,除了其他帖子。

谢谢。

编辑:目前我有这个默认代码来循环每个帖子并显示标题。

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

【问题讨论】:

  • 请向我们展示您已经尝试过的代码,并告诉我们它在哪里不起作用或者您在哪里卡住了。请注意,您也可以尝试发帖:wordpress.stackexchange.com
  • 我已经更新了我的帖子。谢谢

标签: wordpress


【解决方案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(); ?>
...

【讨论】:

  • 并且,如果您想使用内容,请将 'the_excerpt()' 更改为 'the_content()'
【解决方案2】:

也许试试这个...

<?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' =

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-23
    • 1970-01-01
    相关资源
    最近更新 更多