我正在尝试在rss之后进行自定义查询fetch_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://seko.se/feed.rss?rssId=97\' );
if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 3.
$maxitems = $rss->get_item_quantity( 3 );
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items( 0, $maxitems );
endif;
?>
<ul>
<?php if ( $maxitems == 0 ) : ?>
<li><?php _e( \'No items\', \'my-text-domain\' ); ?></li>
<?php else : ?>
<?php // Loop through each feed item and display each item as a hyperlink. ?>
<?php foreach ( $rss_items as $item ) : ?>
<li>
<a href="<?php echo esc_url( $item->get_permalink() ); ?>"
title="<?php printf( __( \'Posted %s\', \'my-text-domain\' ), $item->get_date(\'j F Y | g:i a\') ); ?>">
<?php echo esc_html( $item->get_title() ); ?>
</a>
<div class="news-meta-rss">
<i class="fi-clock"></i><time datetime="<?php the_date(\'Y-m-d\'); ?>"><?php the_time(get_option(\'date_format\')); ?></time>
</div>
</li>
<?php endforeach; ?>
<?php wp_reset_query(); ?>
<?php endif; ?>
</ul>
在这之后,我要做的查询是:
<?php
global $post;
$args = array(
\'numberposts\' => 2,
\'post_type\' => \'nyheter_cpt\',
\'category__not_in\' => array( 157, 150 ),
);
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post);
?>
<div class="large-4 medium-6 small-12 columns">
<div class="panel">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
<a href="<?php the_permalink(); ?>">Läs mer »</a>
<ul class="news-meta">
<li><i class="fi-clock"></i><time datetime="<?php the_date(\'Y-m-d\'); ?>"><?php the_time(get_option(\'date_format\')); ?></time></li>
<li><i class="fi-torso-female"></i><div class="author"><?php the_author(); ?></div></li>
</ul>
</div>
</div>
<?php endforeach; ?>
<?php wp_reset_query(); ?>
如果我将查询放在rss fetch\\u feed请求的上方,查询就可以正常工作,但只要我将其放在下方,就不会显示任何内容。有人知道为什么吗?