0

jqueryタブで切り替える1つの領域にさまざまなフィードを入れようとしています。フィード テンプレートがあり、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 に答える