Last active
December 12, 2022 07:29
-
-
Save takunagai/166f26d9e5c369289c7a658823b4628a to your computer and use it in GitHub Desktop.
[WIdget - Dashboard - Support Widget (Fetch from RSS)] #WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* サポートウィジェット | |
* サポート用外部サイトのRSSを取得し表示 | |
*/ | |
function astra_child_custom_dashboard_support() { | |
?> | |
<p> | |
<a href="#">» Webページで見る</a> | |
<a href="https://sitename.com/form-support" target="_blank">» お問合せ</a> | |
(パスワード:XXXX) | |
</p> | |
<?php | |
include_once( ABSPATH . WPINC . '/feed.php' ); | |
$rss = fetch_feed( 'https://sitename.com/support/feed/' ); // Feed URL | |
if ( ! is_wp_error( $rss ) ) { | |
$maxitems = $rss->get_item_quantity( 24 ); // 取得最大件数 | |
$rss_items = $rss->get_items( 0, $maxitems ); | |
} | |
?> | |
<?php if ( ! empty( $maxitems ) ) : ?> | |
<?php if ( $maxitems === 0 ) : ?> | |
<p>RSS Feed は取得できましたが、記事がありません。</p> | |
<?php else : ?> | |
<ul> | |
<?php foreach ( $rss_items as $item ) : ?> | |
<li> | |
<p style="margin-bottom:0;font-size:1.1em;"><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a><small class="date"><?php echo $item->get_date('Y-m-d'); ?></small></p> | |
<p class="desc" style="margin-top:.25em;"><?php echo mb_substr( strip_tags( $item->get_description() ), 0, 120 ); ?>…</p> | |
</li> | |
<?php endforeach; ?> | |
</ul> | |
<?php endif; ?> | |
<?php else : ?> | |
<p>RSS Feed が取得できませんでした。</p> | |
<?php endif; ?> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment