0

我正在尝试在我使用 jquery 选项卡切换的一个区域中执行不同的提要。我有一个提要模板,每次只需要在其中切换 rss 提要 url。我试图在我的索引页面上为 url 设置一个值,然后在提要中回显它,但我显然没有这样做。我的方法有什么问题?

<----Index Page--->
<div class="news-feed"><?php $url = "http://mysite.com/category/news/feed/"; ?><?php locate_template( array( 'feeds/news-feed.php' ), true ) ?></div>

<-------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('$url');<---WHERE I NEED MY CUSTOM URL
   if (!is_wp_error( $rss ) ) : // Checks that the object is created correctly 
// Figure out how many total items there are, but limit it to 5. 
   $maxitems = $rss->get_item_quantity(5); 

// 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) echo '<li>No items.</li>';
    else
  // Loop through each feed item and display each item as a hyperlink.
    foreach ( $rss_items as $item ) : ?>
      <li>
        <a href='<?php echo esc_url( $item->get_permalink() ); ?>'
        title='<?php echo esc_html( $item->get_title() ); ?>'>
        <?php echo '<img src="' .get_first_image_url($item->get_content()). '"/>'; ?>
        <?php echo esc_html( $item->get_title() ); ?></br>
        <span style="color:#e2e2e2"><?php echo shorten( $item->get_description (),140 ); ?></span></a>
     </li>
 <?php endforeach; ?>
</ul>
4

1 回答 1

0

你需要改变

fetch_feed('$url');

fetch_feed($url);

PHP 中的单引号字符串内部没有扩展变量。

于 2012-02-20T11:02:26.490 回答