dqzpt40064 2016-10-19 20:53
浏览 42

使用导入的RSS提要进行时间转换到Wordpress

I am trying to setup a simple way of ingesting an rss feed into a Wordpress theme I designed. I have it working really well using 'fetch_feed' - all the rss items come through and I can sort them and display them how I need.

The problem I am having is the time shift. The feed I am pulling from is on an Australian server, and the actual feed dates are correct. The client server however I have no idea where it's at, but I set the time zone in the php.ini file as instructed by the hosting company, and yet all of the rss feed items are shifted by 13 hours.

Here is my code for grabbing the rss feed:

<?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;
?>

And this is the code I am using in my theme to display the feed:

<?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; ?>

Any help is greatly appreciated...

  • 写回答

1条回答 默认 最新

  • dsk49208 2016-10-19 21:42
    关注

    Thank you Kevin_Kinsey, I tried the strtotime but even though that didn't do the trick - that did lead me to the answer! Of all things, adding a simple line of PHP

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

    Fixed it! Now all the dates come through in the proper time. Thanks again for your response and willingness to help Kevin!

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘