うさぎのイラスト

ネットアンサー55備忘録

web技術を書いていきます

固定ページ記事をフロントページに掲載

-2015年09月25日-
固定ページに書いた記事やフロントページに共有させる方法です。

その1
固定ページを作成する。
その2
アドバンスカスタムフイールドで投稿させたい固定ページ指定でその項目を作成する。 150927_01
その3
フロントページにその箇所を呼出ましょう。
<?php
$args = array( 
	'pagename' => 'logo'
	);
$the_query = new WP_Query( $args );
// ループ
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
				if( have_rows('ロゴ登録') ):		
					// loop through the rows of data
					while ( have_rows('ロゴ登録') ) : the_row();
						// display a sub field value
							$url=get_sub_field('ロゴurl');
							$img = get_sub_field('ロゴ');
							$imgurl = wp_get_attachment_image_src($img, 'small-thumbnail'); //サイズは自由に変更できる
							if($imgurl){ ?>
							<a href="<?php echo $url; ?>"><img src="<?php echo $imgurl[0]; ?>" alt=""></a>
							<?php } ?>
						<?php
					endwhile;
				else :
					// no rows found
				endif;
				endwhile;
endif;
// 投稿データをリセット
wp_reset_postdata();
?>

参考サイト:notnil