0
1

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] カスタム投稿タイプで投稿した記事からRSSを取得する流れ

Last updated at Posted at 2019-12-27

WordPressのカスタム投稿タイプからRSSにする流れを
メモしておきます。

1.WordPressに「カスタム投稿タイプ」プラグインを導入

追加編集 ※注.各テーマごとに設定する

〜/wp-content/themes/○○○○○(各テーマフォルダ)/functions.php
// カスタム投稿タイプの追加
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'news', // 投稿タイプ名の定義
	array(
			'labels' => array(
			'name' => __( '新着情報' ), // 表示する投稿タイプ名
			'singular_name' => __( '新着情報' )
		),
			'public' => true,
			'menu_position' => 5,
		)
	);
}

ここまでで設定終わり

2.WordPressリロードして投稿

新着情報という枠が出てくるのでそこから投稿可能
※新着情報という見出しはfunctions.phpに追加したところで変更可能

// 省略
'name' => __( '新着情報' ), // 表示する投稿タイプ名
'singular_name' => __( '新着情報' )
// 省略

3.サイト表示&URLにRSS取得のパラメータを書く

http://www.example.com/news/feed/ news以降追加
もしくは
http://www.example.com/feed/?post_type=news feed以降追加

「news」の部分にfunctions.phpで設定した「register_post_type」の第1引数の値を入れる

参考. WordPress カスタム投稿タイプのフィード URLを取得する方法

最後に

3で取得したURLをphp等を利用して情報を抜き出していろんなサイトに埋め込むことが可能です。
その方法はこちらを参照
参考. [php]シンプルなRSSのサンプル

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?