WordPress.org

Ready to get started?Download WordPress

Forums

Featured Post
[PATCH] Custom widget frontends (1 post)

  1. flynsarmy
    Member
    Posted 9 months ago #

    I want to display my featured posts with a layout. Below is a patch that lets you drop a sovit-featured-post.php file in your theme where you can loop through the posts and render however you want.

    Change

    function widget( $args, $instance )
    {
    	extract( $args );
    	$title = apply_filters( 'widget_title', $instance[ 'title' ] );

    to

    function widget( $args, $instance )
    {
    	extract( $args );
    	$title = apply_filters( 'widget_title', $instance[ 'title' ] );
    
    	// Display custom widget frontend
    	if ( $located = locate_template( 'sovit-featured-post.php' ) ) {
    		require $located;
    		return;
    	}

    Example Usage

    Drop sovit-featured-post.php into your theme and add the following:

    <?php
    
    query_posts( 'post_type=' . $instance[ 'post_type' ] . '&showposts=' . $instance[ 'num' ] . '&featured=yes' );
    
    // Don't show this widget if we have no featured posts
    if ( !have_posts() )
    	return;
    
    echo $before_widget;
    
    if ( $title )
    	echo $before_title . $title . $after_title;
    
    echo '<ul>';
    while ( have_posts() ):
    	the_post();
    
    	echo '<li>';
    		the_post_thumbnail();
    	echo '</li>';
    endwhile;
    echo '</ul>';
    
    echo $after_widget;

    The above is a very simple example of showing a list of featured images using your plugin. If no featured images are found, it won't display the widget at all.

    http://wordpress.org/plugins/featured-post/

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.