douzhaochan6468 2015-01-31 19:48
浏览 21
已采纳

Wordpress第一篇文章仅在第一页上与其他文章不同

Got the next code to get the first Wordpress post on only the first page to be different. But it doesn't work. Looked at other questions and answers but there doesn't seem to be a good answer for this.

This is what i've got but isn't working for me:

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

I get this syntax error "unexpected T_ENDWHILE" but can't figure out why. Does anyone know how to properly get this done?

Thanks in advance!

Joeri

  • 写回答

1条回答 默认 最新

  • douyu5775 2015-01-31 19:55
    关注

    It looks like you don't have an endif for that inner if. Perhaps should be:

       <?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; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘