【发布时间】:2016-10-19 20:53:21
【问题描述】:
我正在尝试设置一种将 rss 提要引入我设计的 Wordpress 主题的简单方法。我使用 'fetch_feed' 让它工作得非常好——所有的 rss 项目都通过了,我可以对它们进行排序并按照我的需要显示它们。
我遇到的问题是时移。我从中提取的提要位于澳大利亚服务器上,并且实际提要日期是正确的。客户端服务器,但是我不知道它在哪里,但是我按照托管公司的指示在 php.ini 文件中设置了时区,但是所有的 rss 提要项目都移动了 13 小时。
这是我获取 rss 提要的代码:
<?php // Get RSS Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );
// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed( 'http://xxxxxxxx.com.au/events/feed/' );
if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 25.
$maxitems = $rss->get_item_quantity( 25 );
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items( 0, $maxitems );
endif;
?>
这是我在主题中用于显示提要的代码:
<?php if ( $maxitems == 0 ) : ?>
<h3><?php _e( 'No items', 'my-text-domain' ); ?></h3>
<?php else : ?>
<?php // Loop through each feed item and display each item as a hyperlink. ?>
<?php foreach ( $rss_items as $item ) : ?>
<p><b>
<a href="<?php echo esc_url( $item->get_permalink() ); ?>" target="_blank"
title="<?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date() ); ?>">
<?php echo esc_html( $item->get_title() ); ?>
</a></b>
<?php echo esc_html( $item->get_date('| j F | g:i a') ); ?><br>
<?php echo sanitize_text_field( $item->get_content() ); ?>
</p>
<?php endforeach; ?>
<?php endif; ?>
非常感谢任何帮助...
【问题讨论】:
-
$item->get_date() 在没有格式化参数的情况下返回什么(如果有的话)(换句话说,什么样的默认值)?您也许可以获取此值并使用 strtotime() 或类似的东西来处理它...
-
这是一个好问题 - 我删除了该行并刷新了页面,但没有任何改变。这可能很明显,但我不精通 PHP,所以我提前为我的无知道歉。我会尝试您对 srttotime 选项的建议,谢谢!