フィードを出力する所から失敗しており、
初歩的な質問で大変恐縮ですが、ご教授お願い致します。
前提・実現したいこと
WordPressの固定ページにRSSフィードを作成したい
今後別のフォーマットでのフィード作成する可能性も考慮しております。(元のfeedは残したいです)
発生している問題・エラーメッセージ
そもそものやり方が間違っていたら恐縮なのですが、
記事が出力されません。。
自分で調べたことや試したこと
- テーマ内にpage-smartnews.phpを作成
- 新規固定ページにて/smartnews/を作成
- 1で作成したテンプレートを固定ページ/smartnews/に指定
- page-smartnews.phpの中身をwp-includes/feed-rss2.phpから流用
functions.phpでフックしてしまうと元のfeedが書き変わってしまうのでは?と難航しております。
デフォルトのURL http://xxx.com/feed/
固定ページURL http://xxx.com/feed/smartnews/
該当のソースコード
html
1<?php 2/* 3* Template Name: feed-smartnews 4* Template Post Type: page 5*/ 6?> 7<?php 8/** 9 * RSS2 Feed Template for displaying RSS2 Posts feed. 10 * 11 * @package WordPress 12 */ 13 14header('Content-Type: ' . feed_content_type('rss2') . '; charset=' . get_option('blog_charset'), true); 15$more = 1; 16 17echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; 18 19/** 20 * Fires between the xml and rss tags in a feed. 21 * 22 * @since 4.0.0 23 * 24 * @param string $context Type of feed. Possible values include 'rss2', 'rss2-comments', 25 * 'rdf', 'atom', and 'atom-comments'. 26 */ 27do_action( 'rss_tag_pre', 'rss2' ); 28?> 29<rss version="2.0" 30 xmlns:content="http://purl.org/rss/1.0/modules/content/" 31 xmlns:wfw="http://wellformedweb.org/CommentAPI/" 32 xmlns:dc="http://purl.org/dc/elements/1.1/" 33 xmlns:atom="http://www.w3.org/2005/Atom" 34 xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" 35 xmlns:slash="http://purl.org/rss/1.0/modules/slash/" 36 <?php 37 /** 38 * Fires at the end of the RSS root to add namespaces. 39 * 40 * @since 2.0.0 41 */ 42 do_action( 'rss2_ns' ); 43 ?> 44> 45 46<channel> 47 <title><?php wp_title_rss(); ?></title> 48 <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" /> 49 <link><?php bloginfo_rss('url') ?></link> 50 <description><?php bloginfo_rss("description") ?></description> 51 <lastBuildDate><?php 52 $date = get_lastpostmodified( 'GMT' ); 53 echo $date ? mysql2date( 'D, d M Y H:i:s +0000', $date, false ) : date( 'D, d M Y H:i:s +0000' ); 54 ?></lastBuildDate> 55 <language><?php bloginfo_rss( 'language' ); ?></language> 56 <sy:updatePeriod><?php 57 $duration = 'hourly'; 58 59 /** 60 * Filters how often to update the RSS feed. 61 * 62 * @since 2.1.0 63 * 64 * @param string $duration The update period. Accepts 'hourly', 'daily', 'weekly', 'monthly', 65 * 'yearly'. Default 'hourly'. 66 */ 67 echo apply_filters( 'rss_update_period', $duration ); 68 ?></sy:updatePeriod> 69 <sy:updateFrequency><?php 70 $frequency = '1'; 71 72 /** 73 * Filters the RSS update frequency. 74 * 75 * @since 2.1.0 76 * 77 * @param string $frequency An integer passed as a string representing the frequency 78 * of RSS updates within the update period. Default '1'. 79 */ 80 echo apply_filters( 'rss_update_frequency', $frequency ); 81 ?></sy:updateFrequency> 82 <?php 83 /** 84 * Fires at the end of the RSS2 Feed Header. 85 * 86 * @since 2.0.0 87 */ 88 do_action( 'rss2_head'); 89 90 while( have_posts()) : the_post(); 91 ?> 92 <item> 93 <title><?php the_title_rss() ?></title> 94 <link><?php the_permalink_rss() ?></link> 95<?php if ( get_comments_number() || comments_open() ) : ?> 96 <comments><?php comments_link_feed(); ?></comments> 97<?php endif; ?> 98 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate> 99 <dc:creator><![CDATA[<?php the_author() ?>]]></dc:creator> 100 <?php the_category_rss('rss2') ?> 101 102 <guid isPermaLink="false"><?php the_guid(); ?></guid> 103<?php if (get_option('rss_use_excerpt')) : ?> 104 <description><![CDATA[<?php the_excerpt_rss(); ?>]]></description> 105<?php else : ?> 106 <description><![CDATA[<?php the_excerpt_rss(); ?>]]></description> 107 <?php $content = get_the_content_feed('rss2'); ?> 108 <?php if ( strlen( $content ) > 0 ) : ?> 109 <content:encoded><![CDATA[<?php echo $content; ?>]]></content:encoded> 110 <?php else : ?> 111 <content:encoded><![CDATA[<?php the_excerpt_rss(); ?>]]></content:encoded> 112 <?php endif; ?> 113<?php endif; ?> 114<?php if ( get_comments_number() || comments_open() ) : ?> 115 <wfw:commentRss><?php echo esc_url( get_post_comments_feed_link(null, 'rss2') ); ?></wfw:commentRss> 116 <slash:comments><?php echo get_comments_number(); ?></slash:comments> 117<?php endif; ?> 118<?php rss_enclosure(); ?> 119 <?php 120 /** 121 * Fires at the end of each RSS2 feed item. 122 * 123 * @since 2.0.0 124 */ 125 do_action( 'rss2_item' ); 126 ?> 127 </item> 128 <?php endwhile; ?> 129</channel> 130</rss>

回答1件
あなたの回答
tips
プレビュー