Support » Networking WordPress » feed in wp-admin plugin page with image

  • I am tryin to write a plugin that gets the latest 5 blog entries and displays them with the first image in the post.

    <?php if(function_exists('fetch_feed')) {
    include_once(ABSPATH . WPINC . '/feed.php'); // the file to rss feed generator
    $feed = fetch_feed(''); // specify the rss feed
    $limit = $feed->get_item_quantity(5); // specify number of items
    $items = $feed->get_items(0, $limit); // create an array of items
    if ($limit == 0) echo '<div>Noe har gått galt eller så finnes det ingen artikler.</div>';
    else foreach ($items as $item) : ?>
    <div class="thumb">
    <a href="<?php the_permalink(); ?>">
    <?php echo featured_image_thumb(); ?>
    </div> 	<!-- end .thumb -->
    <h3><a href="<?php echo $item->get_permalink(); ?>" alt="<?php echo $item->get_title(); ?>"><?php echo $item->get_title(); ?></a></h3>
    <p><?php echo $item->get_date('j. F Y @ H:i'); ?></p>
    <?php endforeach; ?>

    and i have timthumb doing the image job. but not getting it tio get the post just the placeholder.

    // Figure out which image to be shown
    function featured_image_thumb() {
    	global $post, $posts;
    	// If a featured image has been set, use the
    	// featured-thumbnail size that was set above with the
    	// class of 'optional_img_class'
    	if (has_post_thumbnail() ) {
    		array('class' => 'featured-img') );
    	// If a featured image is not set, get the first image in
    	// the post content
    	else {
    		$first_img = '';
    		$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
    		$first_img = $matches [1] [0];
    		// Define a default fallback image in case a featured image
    		// is not set and there are no images in the post content
    			$first_img = plugins_url().'/velkommen/placeholder.jpg';
    		// Generate the HTML code to display the image and resize
    		// the image with timthumb.php
    		return '<img class="featured-img" src="'. plugins_url() . '/velkommen/timthumb.php?src=' . $first_img .'&w=200&h=130" alt="" />';
  • The topic ‘feed in wp-admin plugin page with image’ is closed to new replies.