うさぎのイラスト

ネットアンサー55備忘録

web技術を書いていきます

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

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

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

参考サイト:notnil