• 解決済 sasasa24

    (@sasasa24)


    sample-page.php内にカスタム投稿aaaとbbbをそれぞれ呼び出したいです。
    custom posttype UIプラグインと、advance custom fieldプラグインを使っています。

    そこで、sample-page.phpに下記コードを記述しました。

    <?php
    /*
    Template Name:トップページ デモテンプレート
     */
    
    get_header(); ?>
    
    	<div id="primary" class="content-area">
    		<div id="content" class="site-content" role="main">
    
                <div id="aaa" class="section_wrapper">
                	<div class="container">
                    	<div class="row">
                        	<div class="col-sm-12 aaa_new aaa_block">
                                <div class="col-sm-3">
                                    <h3 class="top_title">NEW</h3>
                                    <?php $args = array(
    									'numberposts' => 1,
    									'post_type' => 'aaa'
    								);
    									$customPosts = get_posts($args);
    									if($customPosts) : foreach($customPosts as $post) : setup_postdata( $post ); ?>
                                        	<?php if( get_field('aaa_url') ) { ?>
                                            	<a href="<?php the_field('aaa_url'); ?>" target="_blank">
                                        	<?php } ?>
    											<?php $img = get_field('aaa_img');
                                                    $imgurl = wp_get_attachment_image_src($img, 'large');
                                                    if($imgurl){ ?><img src="<? echo $imgurl[0]; ?>" alt="" class="img-responsive center" />
                                                <? } ?>
                                                </a>
                                    <?php endforeach; ?>
    								<?php endif;
    								 wp_reset_postdata(); //クエリのリセット ?>
                                </div>
                            </div>
                            <div class="col-sm-12 aaa_backnumber aaa_block">
                                <h3 class="top_title">ーーー</h3>
    
                                	<?php $args = array(
    									'numberposts' => 4,
    									'post_type' => 'aaa'
    								);
    								$customPosts = get_posts($args);
    								if($customPosts) : foreach($customPosts as $post) : setup_postdata( $post ); ?>
                                    <div class="col-sm-3">
                                    	<?php if( get_field('aaa_url') ) { ?>
                                            	<a href="<?php the_field('aaa_url'); ?>" target="_blank">
                                        <?php } ?>
    										<?php $img = get_field('aaa_img');
    											$imgurl = wp_get_attachment_image_src($img, 'large');
    											if($imgurl){ ?><img src="<? echo $imgurl[0]; ?>" class="img-responsive center" alt=""></p>
    										<? } ?>
                                    	</a>
                                    </div>
    								<?php endforeach; ?>
    								<?php endif;
    								 wp_reset_postdata(); //クエリのリセット ?>
    
                            </div>
                        </div><!--.row-->
                    </div><!--.container-->
                </div><!--#aaa-->
    
                <div id="bbb" class="section_wrapper">
                	<div class="container">
                    	<div class="row">
                        	<div class="col-sm-12 bbb_new aaa_block">
                                <div class="col-sm-5">
                                <h3 class="top_title">NEW</h3>
                                    <?php $args = array(
    									'numberposts' => 1,
    									'post_type' => 'bbb'
    								);
    									$customPosts = get_posts($args);
    									if($customPosts) : foreach($customPosts as $post) : setup_postdata( $post ); ?>
                                        	<?php if( get_field('bbb_url') ) { ?>
                                            	<a href="<?php the_field('bbb_url'); ?>" target="_blank">
                                        	<?php } ?>
    											<?php $img = get_field('bbb_img');
                                                    $imgurl = wp_get_attachment_image_src($img, 'large');
                                                    if($imgurl){ ?><img src="<? echo $imgurl[0]; ?>" alt="" class="img-responsive center" />
                                                <? } ?>
                                                </a>
                                    <?php endforeach; ?>
    								<?php endif;
    								 wp_reset_postdata(); //クエリのリセット ?>
                                </div>
                            </div>
                        	<div class="col-sm-12 bbb_backnumber aaa_block">
                                <h3 class="top_title">ーーー</h3>
                                	<?php $args = array(
    									'numberposts' => 4,
    									'post_type' => 'bbb'
    								);
    								$customPosts = get_posts($args);
    								if($customPosts) : foreach($customPosts as $post) : setup_postdata( $post ); ?>
                                    <div class="col-sm-3">
                                    	<?php if( get_field('bbb_url') ) { ?>
                                            	<a href="<?php the_field('bbb_url'); ?>" target="_blank">
                                        <?php } ?>
    										<?php $img = get_field('bbb_img');
    											$imgurl = wp_get_attachment_image_src($img, 'large');
    											if($imgurl){ ?><img src="<? echo $imgurl[0]; ?>" class="img-responsive center" alt=""></p>
    										<? } ?>
                                    	</a>
                                    </div>
    								<?php endforeach; ?>
    								<?php endif;
    								 wp_reset_postdata(); //クエリのリセット ?>
    
                            </div>
                        </div>
                    </div>
                </div><!--#bbb-->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    aaaは出力されるのですが、bbbが出力されません。
    同じようにしているのになぜ出力されないのかどなたか教えて頂けないでしょうか。
    よろしくお願いいたします。

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック投稿者 sasasa24

    (@sasasa24)

    自己解決いたしました。
    お騒がせいたしました。

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック「固定ページ内で複数にカスタム投稿を出力したい」には新たに返信することはできません。