Get Featured image from sticky Post in wordpress

Posted: January 29, 2013 in Wordpress

<?php
/**
* Template Name: Sidebar Template
* Description: A Page Template that adds a sidebar to pages
*
* @package WordPress
* @subpackage Twenty_Eleven
* @since Twenty Eleven 1.0
*/
get_header(); ?>

<div id=”figure”>
<?php $sticky = get_option( ‘sticky_posts’ );
$args = array(
‘posts_per_page’ => 1,
‘post__in’  => get_option( ‘sticky_posts’ ),
‘ignore_sticky_posts’ => 1

);

if ( !empty($sticky) ):
// has sticky posts
query_posts($args);

$stickyPosts = new WP_query();
$stickyPosts->query($args);
if ( $stickyPosts->have_posts() ):

while ( $stickyPosts->have_posts() ) : $stickyPosts->the_post();
?>

<div>

<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘single-post-thumbnail’ ); ?>

<img src=”<?php echo $image[0]; ?>”  height=”256″ width=”430″/> // Featured image

<div>

<h1><?php the_title(); ?></h1>
<p> <?php echo substr(strip_tags($post->post_content), 0, 500);?></p>
<a  href=”<?php echo get_permalink($recent[“ID”]);?>”>read more…</a>

<?php
endwhile; //end loop for sticky posts
wp_reset_query();
endif;
endif;
?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s