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

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

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

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

PHP

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

Q&A

解決済

1回答

3942閲覧

スマートニュースのSmartFormatについて

hashidaeri

総合スコア12

WordPress

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

PHP

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

0グッド

0クリップ

投稿2018/10/12 04:02

編集2018/10/12 04:57

PHP初心者です。
現在私はワードプレスで作成しているまとめサイトを運用しています。

運用しているサイトをスマートニュースに掲載させたいと思っています。

http://flappe.guide-book.xyz/column/column-smartnews/
こちらのサイトを参考にスマートニュース用のPHPを作成しました。

チェックツールでは『Valid』(有効)と表示されたので、スマートニュースに申請したところ。

現在、フィード中の各記事が、(オリジナルサイトでの)冒頭ページまでで、途切れてしまっております。

とメールでいただきました。

ワードプレスので作成した記事の2ページ目以降が取得出来ず、表示されない状態になってしまっています。

content:encoded

この中に2ページ目以降も取得する記述がわかりません。

<content:encoded><![CDATA[<?php the_content() ?>]]></content:encoded> <?php else : ?> <content:encoded><![CDATA[<?php the_excerpt_rss() ?>]]></content:encoded> <?php endif; ?>

↑ ↑ ↑
ここを修正すればいいのかと思います。

どなたか2ページ目以降もRSSで取得する方法を教えて頂けませんか?

よろしくお願いいたします。

---------------------追加です!!!---------------------

具体的なコードの全体を記載してください。 

/** * RSS2 Feed Template for displaying RSS2 Posts feed. * * @package smartnews */ header('Content-Type: ' . feed_content_type('rss2') . '; charset=' . get_option('blog_charset'), true); $more = 1; echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; /** * Fires between the xml and rss tags in a feed. * * @since 4.0.0 * * @param string $context Type of feed. Possible values include 'rss2', 'rss2-comments', * 'rdf', 'atom', and 'atom-comments'. */ do_action( 'rss_tag_pre', 'rss2' ); ?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:snf="http://www.smartnews.be/snf" <?php /** * Fires at the end of the RSS root to add namespaces. * * @since 2.0.0 */ do_action( 'rss2_ns' ); ?> > <channel> <title><?php echo bloginfo('name'); ?></title> <snf:logo><url>画像URL</url></snf:logo> <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" /> <link><?php bloginfo_rss('url') ?></link> <description><?php bloginfo_rss("description") ?></description> <lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate> <language><?php bloginfo_rss( 'language' ); ?></language> <sy:updatePeriod><?php $duration = 'hourly'; /** * Filter how often to update the RSS feed. * * @since 2.1.0 * * @param string $duration The update period. Accepts 'hourly', 'daily', 'weekly', 'monthly', * 'yearly'. Default 'hourly'. */ echo apply_filters( 'rss_update_period', $duration ); ?></sy:updatePeriod> <sy:updateFrequency><?php $frequency = '1'; /** * Filter the RSS update frequency. * * @since 2.1.0 * * @param string $frequency An integer passed as a string representing the frequency * of RSS updates within the update period. Default '1'. */ echo apply_filters( 'rss_update_frequency', $frequency ); ?></sy:updateFrequency> <copyright><?php echo get_theme_mod('copy_right_setting'); ?></copyright> <ttl>15</ttl> <image> <url><?php echo esc_url( get_theme_mod( LOGO_IMAGE_URL ) ); ?></url> <title><?php echo bloginfo('name'); ?></title> <link><?php echo site_url(); ?></link> </image> <?php /** * Fires at the end of the RSS2 Feed Header. * * @since 2.0.0 */ do_action( 'rss2_head'); while( have_posts()) : the_post(); ?> <item> <title><?php the_title_rss() ?></title> <link><?php the_permalink_rss() ?></link> <?php if ( get_comments_number() || comments_open() ) : ?> <comments><?php comments_link_feed(); ?></comments> <?php endif; ?> <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate> <?php $thumb_id = get_post_thumbnail_id(); $thumb_url = wp_get_attachment_image_src($thumb_id, 'full'); ?> <?php if(!empty($thumb_url[0])){ ?> <media:thumbnail url="<?php echo $thumb_url[0] ?>" /> <snf:analytics><![CDATA[<script><!-- Analytics埋め込み --></script>]]></snf:analytics> <?php } ?> <?php the_category_rss('rss2') ?> <guid isPermaLink="false"><?php the_guid(); ?></guid> <?php if (get_option('rss_use_excerpt')) : ?> <description><![CDATA[<?php the_excerpt_rss(); ?>]]></description> <?php else : ?> <description><![CDATA[<?php the_excerpt_rss(); ?>]]></description> <?php $content = get_the_content_feed('rss2'); ?> <?php if ( strlen( $content ) > 0 ) : ?> <content:encoded><![CDATA[<?php echo $content; ?>]]></content:encoded> <?php else : ?> <content:encoded><![CDATA[<?php the_excerpt_rss(); ?>]]></content:encoded> <?php endif; ?> <?php endif; ?> <?php if ( get_comments_number() || comments_open() ) : ?> <wfw:commentRss><?php echo esc_url( get_post_comments_feed_link(null, 'rss2') ); ?></wfw:commentRss> <slash:comments><?php echo get_comments_number(); ?></slash:comments> <?php $cat_data = get_the_category(); $cat_list = get_category($cat_data); $query = new WP_Query( array( 'cat' => $cat_list->cat_ID, 'post__not_in' => array($post->ID), 'posts_per_page' => '1', 'offset' => '1', 'post_type' => 'post', 'orderby' => 'rand' )); while($query->have_posts()):$query->the_post(); $rel_thumb_id = get_post_thumbnail_id(); $rel_thumb_url = wp_get_attachment_image_src($rel_thumb_id, 'full'); ?> <snf:relatedLink title="<?php echo the_title_attribute(); ?>" link="<?php the_permalink(); ?>" thumbnail="<?php echo $rel_thumb_url[0]; ?>" /> <?php endwhile; ?> <?php wp_reset_postdata(); ?> <?php endif; ?> <?php rss_enclosure(); ?> <?php /** * Fires at the end of each RSS2 feed item. * * @since 2.0.0 */ do_action( 'rss2_item' ); ?> </item> <?php endwhile; ?> </channel> </rss>

↑ ↑ ↑
こういったPHPになっています。

2ページ目以降

https://ドメイン.com/%year%/%monthnum%/%day%/%postname%/2/

3ページ
https://ドメイン.com/%year%/%monthnum%/%day%/%postname%/3/

4ページ
https://ドメイン.com/%year%/%monthnum%/%day%/%postname%/4/

上記の様にディレクトリの最後に数字が増えていく状態になっております。

---------------------追加です!!!---------------------

https://soysauce-mg.com
運用しているサイトはこちらです。

https://soysauce-mg.com/2018/10/11/doikouza002/

サイト内の記事は
wordpress内のテキストで

<!--nextpage-->

を使用して次のページに切り替わる設定にしています。

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

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

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

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

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

CHERRY

2018/10/12 04:24 編集

参考にされたサイトを元にどのようにコードを記載したのか具体的なコードの全体を記載してください。 「抜粋表示に設定している場合の変更点」とかも対応済みですか?
CHERRY

2018/10/12 04:25 編集

2ページ目以降と書かれてもどのようにページングしているのか不明なので、判断できません。ページングの方法も具体的に記載してください。
hashidaeri

2018/10/12 04:43

CHERRY様 コメントありがとうございます。 質問欄にcode、ページングを記載致しました。 こちらで判断出来ますでしょうか? よろしくお願いいたします。
CHERRY

2018/10/12 04:45 編集

ページングの URL はわかりますが、データは、どのように管理されているのですか?  データの管理方法がわからないと 呼び出せませんが...
hashidaeri

2018/10/12 04:58

CHERRY様 サイトURLを記載していますが、こちらでわかりますか?? ご確認よろしくお願いいたします。
guest

回答1

0

ベストアンサー

<?php if (get_option('rss_use_excerpt')) : ?>

<description><![CDATA[<?php the_excerpt_rss(); ?>]]></description>

<?php else : ?>

<description><![CDATA[<?php the_excerpt_rss(); ?>]]></description>

<?php $content = get_the_content_feed('rss2'); ?> <?php if ( strlen( $content ) > 0 ) : ?>

content:encoded<![CDATA[<?php echo $content; ?>]]></content:encoded>

<?php else : ?>

content:encoded<![CDATA[<?php the_excerpt_rss(); ?>]]></content:encoded>

<?php endif; ?> <?php endif; ?>

の部分で抜粋等の条件判断して、振り分けています。
本文は、$post->post_content に全文が入っているので、強制的に全部を表示するなら、条件判断を全てやめて、こんな感じに置き換えるとどうでしょうか?

PHP

1<?php global $post; ?> 2<description><![CDATA[<?php echo $post->post_content; ?>]]></description>

投稿2018/10/12 05:14

編集2018/10/12 07:06
CHERRY

総合スコア25171

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

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

CHERRY

2018/10/12 05:17 編集

global $post; は、いらなかったかなぁ...  もうすでに宣言されているかもしれないなぁ...
hashidaeri

2018/10/12 06:53

CHERRY様 ありがとうございます。 無知で申し訳ございません。 『条件判断を全てやめて』とありますが、対象のコードがわかりませんでした。。。 ◯◯◯◯◯◯◯◯◯◯◯◯ の代わりに global $post; <description><![CDATA[<?php echo $post->post_content; ?>]]></description> を入れると いうように教えていただきたく存じます。 よろしくお願いいたします。
hashidaeri

2018/10/12 07:01

CHERRY様 <content:encoded><![CDATA[<?php echo $content; ?>]]></content:encoded> 部分を <content:encoded><![CDATA[<?php echo $post->post_content; ?>]]></content:encoded> に変更したら2ページ以降も表示されました。 ありがとうございます!!!!!!!
CHERRY

2018/10/12 07:04

あ、回答を修正したのと行き違いで解決されたようですね。
hashidaeri

2018/10/12 07:07

CHERRY様のお力添えのおかげで無事できました。 本当にありがとうございました!!!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問