Quantcast
Channel: WordPress | サポートフォーラム »投稿一覧
Viewing all articles
Browse latest Browse all 1322

返信先: Warning: Undefined variableのエラーが発生する

$
0
0

複数のサーバー(サイト)で同じ状態になっています。

と、上記で報告しましたが複数サイトのRSSを取得しているサイトについては
「Warning: Undefined variable $maxitems in hoge.php 」のエラーは表示されず、何もなかった場合に表示される「No items.」だけが返されます。

なので「php.ini」の「display_errors」はONのまま運営できていますが、RSSを取得・表示できない場合は同じような頻度で発生しています。

複数RSSを表示しているコード

<?php include_once(ABSPATH . WPINC . '/feed.php');
$rss = fetch_feed(array(
'https://example.com/feed/atom/',
//RSSフィード1

'https://example.com/feed/atom/',
//RSSフィード2

'https://example.com/feed/atom/'
//RSSフィード3

));
if (!is_wp_error( $rss ) ) :
$rss->set_cache_duration(1800);
$rss->init();
$maxitems = $rss->get_item_quantity(6);
$rss_items = $rss->get_items(0, $maxitems);
date_default_timezone_set('Asia/Tokyo');
endif;
?>
<?php if ($maxitems == 0) echo '<li>No items.</li>';
else
foreach ( $rss_items as $item ) : ?>
<div class="hoge01">
<a href='<?php echo $item->get_permalink(); ?>' target="_blank"><?php
$first_img = '';
if ( preg_match( '/<img.+?src=[\'"]([^\'"]+?)[\'"].*?>/msi', $item->get_content(), $matches ) ) {
$first_img = $matches[1];
}
?>
<?php if ( !empty( $first_img ) ) : ?><img src="<?php echo esc_attr( $first_img ); ?>" alt="" ></a>
</div>
<?php endif; ?>
<?php endforeach; ?>

phpのコード自体に問題があるのか、その他に原因があるのかすらわからない状態です。
ご助言いただけませんでしょうか。

よろしくお願いします。


Viewing all articles
Browse latest Browse all 1322

Trending Articles