【问题标题】:Wordpress first post only on first page different then othersWordpress 第一篇文章仅在第一页上与其他页面不同
【发布时间】:2023-07-10 10:05:01
【问题描述】:

获得了下一个代码,以使第一页上的第一个 Wordpress 帖子有所不同。但它不起作用。查看了其他问题和答案,但似乎没有一个很好的答案。

这是我所拥有的,但对我不起作用:

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('posts_per_page' => 5, 'paged' => $paged );
query_posts($args); ?>

<?php if (have_posts()) : ?>
<?php $postcount = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php $postcount++; ?>

    <?php if ($postcount == 1 && $paged == 1) : // if this is the first post & first page ?>
    <div class="large-10">
    <?php the_post_thumbnail('large'); ?>
    </div>

        <?php else : //if this is NOT the first post ?>         
        <div class="large-6 columns">
        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <div class="portfolio">
            <a href="<?php the_permalink(); ?>">
            <?php the_post_thumbnail('large'); ?>
            <span><h6><?php the_title(); ?></h6></span>
            </a>
        </div>

        </article>
        </div>

    <?php endwhile; ?>
<?php endif; ?>

我收到此语法错误“意外的 T_ENDWHILE”,但不知道原因。 有谁知道如何正确完成这项工作?

提前致谢!

乔里

【问题讨论】:

    标签: php wordpress loops post


    【解决方案1】:

    您的内部if 似乎没有endif。也许应该是:

       <?php if ($postcount == 1 && $paged == 1) : // if this is the first post & first page ?>
        <div class="large-10">
        <?php the_post_thumbnail('large'); ?>
        </div>
    
        <?php else : //if this is NOT the first post ?>         
            <div class="large-6 columns">
            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
            <div class="portfolio">
                <a href="<?php the_permalink(); ?>">
                <?php the_post_thumbnail('large'); ?>
                <span><h6><?php the_title(); ?></h6></span>
                </a>
            </div>
    
            </article>
            </div>
       <?php endif; ?>
    

    【讨论】:

    • 我的.. 完全错过了.. 感谢您的快速回答!
    • 现在我已经想出了整个代码和东西;)关于如何在第一页上显示与其他页面不同数量的帖子的任何想法。这是因为它是一个 2 列界面,现在第一页上的较小帖子不均匀.. 会让我开心!干杯
    • @user3241326,如果答案是正确的,点赞并接受它会让人们知道!
    最近更新 更多