質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
XML

XMLは仕様の1つで、マークアップ言語群を構築するために使われています。

RSS

RSS(Really Simple Syndication)はブログのエントリやニュースの見出し、標準のフォーマットの音声やビデオなどを発行するために使われるウェブフィードのフォーマットの集合体です。

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

Q&A

0回答

4206閲覧

カスタムRSSが/feedで表示できない。

nkgtoshiii

総合スコア0

XML

XMLは仕様の1つで、マークアップ言語群を構築するために使われています。

RSS

RSS(Really Simple Syndication)はブログのエントリやニュースの見出し、標準のフォーマットの音声やビデオなどを発行するために使われるウェブフィードのフォーマットの集合体です。

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

0グッド

1クリップ

投稿2021/08/26 21:34

前提・実現したいこと

WordPressにてRSSカスタムテンプレートを作成して、それを/feedにて表示させたい。

発生している問題・エラーメッセージ

/feedで確認すると、下記エラーメッセージが表示される。

This page contains the following errors: error on line 2 at column 1: Extra content at the end of the document Below is a rendering of the page up to the first error.

該当のソースコード

functions.phpには下記の記述を行っています。

php

1//RSSをテーマ内から読み込む 2remove_filter('do_feed_rss2', 'do_feed_rss2', 10); 3function custom_feed_rss2(){ 4$template_file = '/feed-rss2.php'; 5load_template(get_template_directory() . $template_file); 6} 7add_action('do_feed_rss2', 'custom_feed_rss2', 10); 8?>

WordPressのwp-includesフォルダ内の『feed-rss2.php』を
コピーし、現在使用しているテーマディレクトリに複製しました。
そちらのコードは下記です。

php

1<?php 2/** 3 * RSS2 Feed Template for displaying RSS2 Posts feed. 4 * 5 * @package WordPress 6 */ 7 8header( 'Content-Type: ' . feed_content_type( 'rss2' ) . '; charset=' . get_option( 'blog_charset' ), true ); 9$more = 1; 10 11echo '<?xml version="1.0" encoding="' . get_option( 'blog_charset' ) . '"?' . '>'; 12 13/** 14 * Fires between the xml and rss tags in a feed. 15 * 16 * @since 4.0.0 17 * 18 * @param string $context Type of feed. Possible values include 'rss2', 'rss2-comments', 19 * 'rdf', 'atom', and 'atom-comments'. 20 */ 21do_action( 'rss_tag_pre', 'rss2' ); 22?> 23<rss version="2.0" 24 xmlns:content="http://purl.org/rss/1.0/modules/content/" 25 xmlns:wfw="http://wellformedweb.org/CommentAPI/" 26 xmlns:dc="http://purl.org/dc/elements/1.1/" 27 xmlns:atom="http://www.w3.org/2005/Atom" 28 xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" 29 xmlns:slash="http://purl.org/rss/1.0/modules/slash/" 30 <?php 31 /** 32 * Fires at the end of the RSS root to add namespaces. 33 * 34 * @since 2.0.0 35 */ 36 do_action( 'rss2_ns' ); 37 ?> 38> 39 40<channel> 41 <title><?php wp_title_rss(); ?></title> 42 <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" /> 43 <link><?php bloginfo_rss( 'url' ); ?></link> 44 <description><?php bloginfo_rss( 'description' ); ?></description> 45 <lastBuildDate><?php echo get_feed_build_date( 'r' ); ?></lastBuildDate> 46 <language><?php bloginfo_rss( 'language' ); ?></language> 47 <sy:updatePeriod> 48 <?php 49 $duration = 'hourly'; 50 51 /** 52 * Filters how often to update the RSS feed. 53 * 54 * @since 2.1.0 55 * 56 * @param string $duration The update period. Accepts 'hourly', 'daily', 'weekly', 'monthly', 57 * 'yearly'. Default 'hourly'. 58 */ 59 echo apply_filters( 'rss_update_period', $duration ); 60 ?> 61 </sy:updatePeriod> 62 <sy:updateFrequency> 63 <?php 64 $frequency = '1'; 65 66 /** 67 * Filters the RSS update frequency. 68 * 69 * @since 2.1.0 70 * 71 * @param string $frequency An integer passed as a string representing the frequency 72 * of RSS updates within the update period. Default '1'. 73 */ 74 echo apply_filters( 'rss_update_frequency', $frequency ); 75 ?> 76 </sy:updateFrequency> 77 <?php 78 /** 79 * Fires at the end of the RSS2 Feed Header. 80 * 81 * @since 2.0.0 82 */ 83 do_action( 'rss2_head' ); 84 85 while ( have_posts() ) : 86 the_post(); 87 ?> 88 <item> 89 <title><?php the_title_rss(); ?></title> 90 <link><?php the_permalink_rss(); ?></link> 91 <?php if ( get_comments_number() || comments_open() ) : ?> 92 <comments><?php comments_link_feed(); ?></comments> 93 <?php endif; ?> 94 95 <dc:creator><![CDATA[<?php the_author(); ?>]]></dc:creator> 96 <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate> 97 <?php the_category_rss( 'rss2' ); ?> 98 <guid isPermaLink="false"><?php the_guid(); ?></guid> 99 100 <?php if ( get_option( 'rss_use_excerpt' ) ) : ?> 101 <description><![CDATA[<?php the_excerpt_rss(); ?>]]></description> 102 <?php else : ?> 103 <description><![CDATA[<?php the_excerpt_rss(); ?>]]></description> 104 <?php $content = get_the_content_feed( 'rss2' ); ?> 105 <?php if ( strlen( $content ) > 0 ) : ?> 106 <content:encoded><![CDATA[<?php echo $content; ?>]]></content:encoded> 107 <?php else : ?> 108 <content:encoded><![CDATA[<?php the_excerpt_rss(); ?>]]></content:encoded> 109 <?php endif; ?> 110 <?php endif; ?> 111 112 <?php if ( get_comments_number() || comments_open() ) : ?> 113 <wfw:commentRss><?php echo esc_url( get_post_comments_feed_link( null, 'rss2' ) ); ?></wfw:commentRss> 114 <slash:comments><?php echo get_comments_number(); ?></slash:comments> 115 <?php endif; ?> 116 117 <?php rss_enclosure(); ?> 118 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> 131

試したこと

①functions.phpに空行や全角スペースがないか確認→なし
②wp-includesファイルにあるfeed-rss2.phpに「ob_end_clean();」を追記
③W3C Feed Validation Serviceで確認
下のメッセージがでてきました。

Server returned HTTP Error 500: Internal Server Error [help] Sorry An error occurred while trying to validate this feed. Possible causes: The address may be incorrect. Make sure the address is spelled correctly. Try loading the feed directly in your browser to make sure a feed exists at that address. The feed may be temporarily unavailable. The server may be down, or too slow. Try again later. The validator may be busted. If the feed exists, the server is fine, and the problem is reproducible, please raise an issue.

補足情報(FW/ツールのバージョンなど)

W3C Feed Validation Serviceで確認したメッセージはどこを修正すればよいかわからない状態です。
お力をおかしいただければ幸いです。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

etherbeg

2021/08/27 12:01

実際に出力されたRSSファイルの内容を質問に追記していただくことはできますか?
nkgtoshiii

2021/08/27 12:13 編集

コメントありがとうございます! RSSの内容はブラウザに表示されずに、下記のメッセージがブラウザに表示される状況です。 This page contains the following errors: error on line 2 at column 1: Extra content at the end of the document Below is a rendering of the page up to the first error. 申し訳ございませんがご確認いただければ幸いです。
etherbeg

2021/08/27 12:21

確認って何を確認するのですか? PHPで動的に生成したfeedってファイルには保存されずにクライアントに送信されるだけなんでしたっけ。 PHPのプログラムに、feedをファイルに保存するコードを追加して、生成されているfeedの内容を確認することはできませんか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問