0

選択したときに 1 つのカテゴリから 1 つの投稿を取得するループを wordpress で作成しようとしていますが、そうでない場合は、呼び出しているカスタム投稿タイプから最新の投稿を表示する必要があります。例: お客様の声、最新ニュース、ケース スタディ。

これが私が持っているものです。ifelse が必要ですか。猫が存在しない場合にクエリを実行し、その CPT の最新の投稿を表示するステートメント。

これが私が持っているコードです。

  <?php
                $query = new WP_Query('post_type=testimonial&catergory_name=home&showposts=1&paged=' . $paged);
                $postcount = 0;
            ?>
            <?php if ($query->have_posts()) : ?>
                <?php while ($query->have_posts()) : $query->the_post(); ?>
                    <?php $postcount++; ?>
                    <li> 
                     <A HREF="<?php the_permalink(); ?>"></A>
 <a href="<?php the_permalink(); ?>">
                        <?php
                            if (has_post_thumbnail()) {
                                // check if the post has a Post Thumbnail assigned to it.
                                the_post_thumbnail('thumb-casestudy');
                            }else {
                            ?>
                            <img src="<?php bloginfo('template_url'); ?>/assets/images/default.jpg" alt="<?php the_title(); ?>"/>
                            <?php } ?>
 </a>
                        <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                        <p class="hm_text"><?php 
                                //the_excerpt(); 
                                echo get_post_meta($query->post->ID, 'wpld_cf_home_page_text', true) 
                        ?></p>




                    </li>
                    <?php endwhile; ?>
                <?php else : ?>
                <?php endif; ?>
4

1 に答える 1