Help us understand the problem. What is going on with this article?

WordPressにグノシー向けのフィードを追加

WordPressにスマートニュース向けのフィードを追加
に続いて。

GunosyFeed Ver.3 仕様書/手順書
GunosyFeedValidator

/path/to/theme/functions.php
//フィード追加
add_action('init', function() {
    add_feed('gunosy', function() { get_template_part('/feed/gunosy'); });
});

//クエリ変更
add_action('pre_get_posts', function($query) {
    if ( is_admin() ) return $query;
    if ( $query->is_main_query() && $query->is_feed('gunosy') ) {
        //投稿タイプ変更or追加
        $query->set('post_type', ['post', 'any']);
        //削除に対応する場合
        $query->set('post_status', ['publish', 'trash']);
    }
    return $query;
});

リライトルールを追加するので
設定>パーマリンク設定で更新。

※ATOM準拠

/path/to/theme/feed/gunosy.php
<?php
header('Content-Type: ' . feed_content_type('atom') . '; charset=' . get_option('blog_charset'), true);
$more = 1;

echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>';
do_action( 'rss_tag_pre', 'atom' );
?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en" xmlns:gnf="http://assets.gunosy.com/media/gnf" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/">
    <title><?php echo get_option('blogname');?></title>
    <link type="text/html" href="<?php echo home_url('/');?>" rel="alternate"/>
    <subtitle><?php echo get_option('blogdescription');?></subtitle>
    <updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT'), false); ?></updated>
    <rights>【コピーライト】</rights>
    <logo>【正方形ロゴ】</logo>
    <gnf:wide_image_link>【縦44px横長ロゴ】</gnf:wide_image_link>
<?php
while ( have_posts() ) : the_post(); global $post;
?>
    <entry>
        <title><![CDATA[<?php the_title_rss();?>]]></title>
        <link type="text/html" href="<?php the_permalink_rss();?>" rel="alternate"/>
        <id><?php the_ID();?></id>
        <published><?php echo get_post_time(DATE_RFC3339, true);?></published>
        <updated><?php echo get_post_modified_time(DATE_RFC3339, true);?></updated>
        <summary><?php the_excerpt_rss();?></summary>
        <content><![CDATA[
<?php if ( has_post_thumbnail() ):?>
            <figure>
                <img src="<?php echo get_the_post_thumbnail_url($post->ID, 'large');?>">
                <figcaption><?php echo get_the_post_thumbnail_caption($post->ID);?></figcaption>
            </figure>
<?php endif;?>
<?php the_content_feed('atom');?>
        ]]></content>
        <gnf:category>any</gnf:category>
<?php
$categories = get_the_category($post->ID);
if ( !empty($categories) ):
    $cats = [];
    foreach ($categories as $category) {
        if ( !in_array($category->name, $cats) ) $cats[] = $category->name;
        if ( count($cats) >= 10 ) break;
    }
?>
        <gnf:keyword><?php echo implode(',', $cats);?></gnf:keyword>
<?php endif;?>
<?php if ( has_post_thumbnail() ):?>
        <link rel="enclosure" type="image/jpeg" title="<?php echo get_the_post_thumbnail_caption();?>" href="<?php echo get_the_post_thumbnail_url($post->ID, 'large');?>" />
<?php endif;?>
        <media:status state="<?php echo $post->post_status=='publish' ? 'active' : 'deleted';?>" />
<?php do_action( 'atom_entry' );?>
    </entry>
<?php endwhile;?>
</feed>

content内にスクリプトが使えないので
twitterやinstagramのウィジェット入れてる場合は<script>だけ除去する処理を入れる。

アナリティクスのタグとか関連記事などは適宜追記を。

ki6ool
絶対ワードプレス使うマン
https://6oolab.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした