14
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WordPressのスターターコンテンツ用スニペットメモ

Last updated at Posted at 2017-02-11

WordPress4.7から使えるようになったスターターコンテンツ。
自力でカスタマイズすることもできるのですが、サンプルコードがあまり見当たらなかったので、自分用メモにしてたのアップします。

##投稿を設定する

固定ページを追加する

home / about / contact / blogの固定ページがそれぞれ存在しない場合、自動で生成する。
オプションを指定しない場合、コアに定義された規定のタイトルと本文だけが設定される。
(標準で定義されている固定ページはhome, about, contact, blog, news, homepage-sectionの6種類)

    add_theme_support(
        'starter-content', [
        'posts' => [
            'home',
            'about',
            'contact',
            'blog',
        ],
    ]);

####Blog記事を1つ用意したい場合のサンプル

追加分のBlog記事については、カスタマイザー上ではプレビューできないが、適用後に反映される。

    add_theme_support(
        'starter-content', [
        'posts' => [
            'custom' => [
                'post_type' => 'post',
                'post_title' => 'Hello, Dolly',
                'post_excerpt' => 'This is a example Starter Contnet Blog post.',
                'post_name' => 'example-blog-post',
                'post_content' => "Hello, Dolly
Well, hello, Dolly
It's so nice to have you back where you belong
You're lookin' swell, Dolly
I can tell, Dolly
You're still glowin', you're still crowin'
You're still goin' strong
We feel the room swayin'
While the band's playin'
One of your old favourite songs from way back when
So, take her wrap, fellas
Find her an empty lap, fellas
Dolly'll never go away again
Hello, Dolly
Well, hello, Dolly
It's so nice to have you back where you belong
You're lookin' swell, Dolly
I can tell, Dolly
You're still glowin', you're still crowin'
You're still goin' strong
We feel the room swayin'
While the band's playin'
One of your old favourite songs from way back when
Golly, gee, fellas
Find her a vacant knee, fellas
Dolly'll never go away
Dolly'll never go away
Dolly'll never go away again",
                'comment_status' => 'closed',
            ]
        ],
    ]);

##メディアファイルを設定する
###Aboutページにサムネイル画像を設定する

add_theme_support( 'starter-content', array(
    'attachments' => array(
        'featured-image-logo' => array(
            'post_title' => 'Featured Logo',
            'post_content' => 'Attachment Description',
            'post_excerpt' => 'Attachment Caption',
            'file' => 'assets/images/featured-logo.jpg',
        ),
    ),
    'posts' => array(
        'about' => array(
            'thumbnail' => '{{featured-image-logo}}',
        ),
    ),
);

##フロントページを設定する

optionsでフロントページを設定できる。
{{NAME}}でNAMEにpostsの値を入れることができる。

####home``blogの固定ページを作成して、固定フロントページはhome / Blogはblogに設定する

    add_theme_support(
        'starter-content', [
        'options' => [
            'show_on_front' => 'page',
            'page_on_front' => '{{home}}',
            'page_for_posts' => '{{blog}}',
        ],
        'posts' => [
            'home',
            'blog'
        ],
    ]);

##ナビゲーションを設定する

    add_theme_support(
        'starter-content', [
	     'nav_menus' => [
	            'sample_navigation' => [
	                'name' => __('Sample Navigation', 'id'),
	                'items' => [
	                  'home_link',
	                  'page_about',
						'custome_page' => [
							'title' => 'Contact Page',
							'url' => 'page_contact',
						],
						'custome_link' => [
							'title' => 'Sample',
							'url' => 'http://google.com',
						],
	                ],
	            ]
	     ],
    ]);

##ウィジェットを設定する

add_theme_support(
  'starter-content', [
	'widgets' => [
		'home-content-top-widget-area' => [
			'search',
			'archives',
			'text_custom' => [
				'text',
				[
					'title' => 'Pre-hydrated text widget.',
					'text' => 'Sample'
				]
			],
			'meta_custom' => [
				'meta',
				[
					'title' => 'Pre-hydrated meta widget.',
				]
			],
		],
	],
  ]
);

##プラグインで追加されたウィジェットを設定する(VK_Profile)

// Plugin widget added using filters
function myprefix_starter_content_add_widget( $content, $config ) {
    if ( isset( $content['widgets']['home-content-top-widget-area'] ) ) {
	    $content['widgets']['front-side-top-widget-area']['b_custom_widget'] = array(
			'wp_widget_vkexunit_profile', array(
				'label' => 'Sample profile widget',
				'facebook' => 'http://facebook.com',
				'profile' => 'profile content'
			),
		);
    }
    return $content;
}
add_filter( 'get_theme_starter_content', 'myprefix_starter_content_add_widget', 10, 2 );
14
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?