Support » Plugins » Hacks » help with appending a function to the_content

  • Hello, I’m trying to create a simple program that appends a set of RSS links using WordPress’s built in RSS parser for my website and have I have the parsing code working great, its pretty much the same example for the fetch_feed on this site but I am learning as I go and mean to share everything on my blog for anyone who is interested, so I am not pretending to be an expert on anything. But anyways, the problem I’m having is that I can’t get the links to show up after the content, even by concatenating after the $content variable. I had this problem before and I fixed it by returning a value in my function but I don’t know how to do that if I want all 5 links to show up! Here is the code:

    require_once(ABSPATH . WPINC . '/feed.php');
    require_once(ABSPATH . WPINC . '/post.php');
    global $post;
    function WP_Get_The_Feed () {
    $rss = fetch_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 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);
    if ($maxitems == 0) echo '<li>No items.</li>';
        // Loop through each feed item and display each item as a hyperlink.
        foreach ( $rss_items as $item ) : 
    	$theurl = $item->get_permalink();
    	$thetitle = $item->get_title();
        $thefeedstuff = "<li><a href= $theurl>$thetitle</a></li>";
    	echo $thefeedstuff;
    	//end the loop.
    	//function specifically for adding the links to the end of the post.
    	function WP_Append_The_Links($content)
    	return $content.Wp_Get_The_Feed();
    	add_filter('the_content', 'WP_Append_The_Links');
  • The topic ‘help with appending a function to the_content’ is closed to new replies.