こちらの記事を元にnoteの投稿をRSSフィードを用いてWordPress内に表示させる実装を行いました。
https://tane-be.co.jp/knowledge/web-design/3349/
ロリポップのサーバーでは正しく表示をされています。
お客様のご利用のサーバーがエックスサーバーのため、
試しにエックスサーバーに契約し、その環境でwordpressを作成するとエラーメッセージが出るようになりました。
(エックスサーバーは現在無料期間)
あまりphpに詳しくなく、原因が分からず困っております。
どのように修正したら良いか、解決法を教えていただけないでしょうか?
発生している問題
表示をしたいものはすべて正しく表示されているものの
エラーメッセージが出ている。
発生している問題・エラーメッセージ
アイキャッチの上に下記エラーメッセージが出ます。 Warning : file_get_contents(https://note.mu/api/v1/notes/⚪︎⚪︎⚪︎): failed to open stream: HTTP request failed! HTTP/1.1 405 Method Not Allowed in /⚪︎⚪︎⚪︎/functions.php on line 72
該当のソースコード
function note_feed_display($feedURL, $num, $length) { if(!$feedURL) { return false; } if(!$num) { $num = 3; } if(!$length) { $length = 20; } include_once( ABSPATH . WPINC . '/feed.php' ); $rss = fetch_feed( $feedURL ); if ( !is_wp_error( $rss ) ) { $maxitems = $rss->get_item_quantity($num); $rss_items = $rss->get_items( 0, $maxitems ); } if ( !empty( $maxitems ) ) { if ($maxitems == 0){ echo '<!-- RSSデータがありません -->'; } else { echo '<ul class="list">'; foreach ( $rss_items as $item ) { $hash = substr($item->get_link(), strrpos($item->get_link(), '/') + 1); $api_data = file_get_contents('https://note.mu/api/v1/' . 'notes/' . $hash); $eyecatch = $item->data["child"]["http://search.yahoo.com/mrss/"]["thumbnail"][0]["data"]; $creatorImg = $item->data["child"]["https://note.com"]["creatorImage"][0]["data"]; $creatorName = $item->data["child"]["https://note.com"]["creatorName"][0]["data"]; $first_img = ''; if ( preg_match('/<img.+?src=[\'"]([^\'"]+?)[\'"].*?>/msi', $item->get_content(), $matches) ) { $first_img = $matches[1]; } $description = $item->get_description(); $description = str_replace("続きをみる", "", $description); $description = strip_tags($description); if($length != 0) { $description = mb_strimwidth($description, 0, $length, "...", 'utf-8'); } echo '<li class="col">'; echo '<article class="card">'; echo '<a href="'.$item->get_permalink().'" class="card-wrapper" target="_blank" rel="noopener noreferrer">'; /** * アイキャッチ * ないときは、投稿内の1枚目の画像を * それもないときは、ダミー画像を表示させる */ if (!empty($eyecatch)){ echo '<figure class="card-thumbnail"><img src="'.$eyecatch.'" alt="'.$item->get_title().' eyecatch"></figure>'; } elseif (empty($eyecatch) && !empty($first_img)) { echo '<figure class="card-thumbnail"><img src="'.esc_attr($first_img).'" alt="'.$item->get_title().'" /></figure>'; } else { echo '<figure class="card-thumbnail"><img src="<!-- ダミー画像のパス -->" alt="'.$item->get_title().'" /></figure>'; } echo '<div class="card-contents">'; echo '<h3 class="card-title">'.$item->get_title().'</h3>'; echo '<p class="card-description">'.$description.'</p>'; echo '<time class="card-date">'.$item->get_date('Y.m.d').'</time>'; echo '<div class="card-author">'; echo '<div class="card-author-img"><img src="'.$creatorImg.'" alt="'.$creatorName.'"></div>'; echo '<div class="card-author-name">'.$creatorName.'</div>'; echo '</div>'; echo '</div>'; echo '</a>'; echo '</article>'; echo '</li>'; } echo '</ul>'; } } } エラーの72に該当する部分 →$api_data = file_get_contents('https://note.mu/api/v1/' . 'notes/' . $hash);

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