首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress循环-前4篇文章有不同的结构(PHP错误)

Wordpress循环-前4篇文章有不同的结构(PHP错误)
EN

Stack Overflow用户
提问于 2010-12-08 02:21:14
回答 2查看 337关注 0票数 0

嘿,我对PHP不太在行,非常新手。但这表明了一个错误。

代码语言:javascript
复制
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();  
                  $loopcounter++; ?> 

            <?php if ($loopcounter  == 1) { ?>
                <section class="post" class="postFeatured">
                <h1 class="post"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
            <?php } else { ?>
                <section class="post" class="postSmall">
                <h2 class="post"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
            <?php } ?>

                    <div class="image">
                        <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" class="imgHolder">
                            <div class="img">
                                <div class="cc"><span class="number"><?php comments_number('0', '1', '%'); ?></span><span class="txt">COMMENTS</span></div>
                                <?php $image = get_post_meta($post->ID, 'image', true); ?>
                                <img src="<?php echo $image; ?>" alt="<?php the_permalink() ?>" />
                            </div>
                        </a>
                    </div>

                    <ul class="postDetail">
                        <li class="dateAuth">
                            <div class="dMY"><?php the_time('d M Y') ?></div>
                            <div class="author">Posted by <?php the_author_posts_link() ?></div>
                        </li>
                        <li class="categories">
                            <div class="cats"><?php the_category(', ') ?></div>
                        </li>
                    </ul>

                    <div class="entry excerpt">
                        <?php the_excerpt(); ?>
                        <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>" class="read-more">Read Article</a>
                    </div>

                </section>
            <?php } endwhile; endif; ?>

不知道为什么,有人能帮我吗?

还原

代码语言:javascript
复制
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post();  
      $loopcounter++; ?> 
        <div class="post">
<?php if ($loopcounter  == 1) { ?>
         <h1 class="first"><?php the_title(); ?></h1>
<?php } else { ?>
         <h1 class="second"><?php the_title(); ?></h1>
<?php } ?>
        <?php the_content(); ?>
        </div>
<?php } endwhile; endif; ?>

错误的结果是:<?php } endwhile; endif; ?>

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-12-08 02:46:04

丢失endwhile之前的关闭大括号。

此外,endif也是多余的。

票数 3
EN

Stack Overflow用户

发布于 2010-12-08 02:49:43

在结束前的最后一个卷曲大括号与任何开口的卷曲大括号不匹配。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4383645

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档