Flexible Posts Widget
[resolved] Editing The Template (3 posts)

  1. Xarcell
    Posted 2 years ago #

    I'm wanting to have a different template to use other than the widget.php, simply because I am using/making a responsive horizontal theme and I need little more flexibility.

    I have already cloned the "widget.php" and named it "dashboard-widget.php".

    How can I make the featured image or image in the post, appear as the background of the list item? CSS & HTML is my thing, but not PHP...


    <li id="post-<?php the_ID(); ?>" <?php post_class(); ?> style="background: url(GRAB_THE_URL) center center no-repeat;">



  2. DaveE
    Plugin Author

    Posted 2 years ago #

    Hi Xarcell,

    Something like this should do the trick:

    	// Get the feature image source for use as background...
    	$src = $style = '';
    	if( has_post_thumbnail() ) {
    		$src = wp_get_attachment_image_src( get_post_thumbnail_id(), 'project-large' );
    		$style = ' style="background:url(' . $src[0] . ') center center no-repeat;" ';
    <li id="post-<?php the_ID(); ?>" <?php post_class(); ?><?php echo $style; ?>>

    In this example, I'm getting the feature image's source URL using wp_get_attachment_image_src() and then setting <li> style attribute to the use that image source for the background image.


  3. DaveE
    Plugin Author

    Posted 2 years ago #

    Hi Xarcell,

    Since I haven't heard that you are still having trouble I'm going to close this thread. Feel free to respond and reopen it if you still have trouble.


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Flexible Posts Widget
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.