0

これが他の場所で回答されている場合はお詫びしますが、これはおそらく最も基本的な WordPress ループの質問であり、私には理解できないようです. このページにはカスタム カテゴリがあります。この領域は、以下のコードに従って「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 に答える