WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Xarcell
    Member
    Posted 8 months 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...

    Example:

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

    Thanks.

    http://wordpress.org/plugins/flexible-posts-widget/

  2. DaveE
    Member
    Plugin Author

    Posted 8 months ago #

    Hi Xarcell,

    Something like this should do the trick:

    <?php
    	// 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.

    Cheers,

  3. DaveE
    Member
    Plugin Author

    Posted 8 months 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.

    Cheers!

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.