时间移动与导入RSS提要到Wordpress



我正在尝试设置一个简单的方法来摄取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; ?>

谢谢你Kevin_Kinsey,我尝试了strtotime,但即使它没有奏效-它确实让我找到了答案!最重要的是,添加一行PHP

<?php
date_default_timezone_set("Australia/Sydney");
?>

固定!现在所有的日期都在适当的时间通过。再次感谢您的回复和帮助Kevin的意愿!

最新更新