0

如果这已在其他地方得到回答,我表示歉意,但这可能是最基本的 WordPress 循环问题,我似乎无法弄清楚。我在此页面上有一个自定义类别:http: //goo.gl/J4FdhX位于中间列的底部,称为“珠宝”。这个区域应该根据下面的代码拉一个“home-thumbnail”和“the_excerpt”。我忽略了什么吗?任何事情都有帮助。

 <div class="six columns post-bg">
                                            <div class="post-bg-wrapper sameheight">
                                               <h2>JEWELRY</h2>
                                            <?php
                                            $args = array(
                                                'posts_per_page' => 1,
                                                'category' => 'jewelry',
                                            );

                                            // The Query
                                            $query = new WP_Query( $args );

                                            // The Loop
                                            if ( $query->have_posts('') ) {
                                                while ( $query->have_posts('') ) {
                                                    $query->the_post(); ?>
                                                    <?php the_excerpt(); ?>
                                                         <?php if ( has_post_thumbnail()) : ?>
                                                    <div class="center img">
                                                        <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
                                                           <?php the_post_thumbnail('home-thumbnail'); ?>
                                                        </a>
                                                    </div>
                                                         <?php endif; ?>
                                                    <p class="primary-link"><a href="<?php the_permalink(); ?>">Read More</a></p>
                                            <?php   }
                                            }
                                            wp_reset_postdata();
                                            ?>
                                             </div>
                                        </div>

提前致谢!

4

1 回答 1

0

我认为您刚刚在 have_posts() 中插入了一个额外的 '' 。其他 看起来还可以。

if ( $query->have_posts('') ) {
                                            while ( $query->have_posts('') )

如果它还没有解决这个问题..,请告诉我,将详细说明和调试您的代码

于 2013-10-16T05:56:00.893 回答