WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Editing The Template

[Resolved] Editing The Template

  • 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/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author DaveE
    Member

    @dpe415

    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,

    Plugin Author DaveE
    Member

    @dpe415

    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!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Editing The Template’ is closed to new replies.