• Resolved Limjunk

    (@tombooth01)


    Thanks for creating this plugin, I was looking around for quite some time for a post-based banner for a site. Your plugin does the trick – however I did make one small change as I only wanted PUBLISHED posts to appear and if there were NONE then the widget wouldn`t display.

    It was a simple change to your code below:

    `// Variables from the widget settings.

    $show_custom_post_title = isset( $instance[‘show_custom_post_title’] ) ? $instance[‘show_custom_post_title’] : false;

    $show_featured_image = isset($instance[‘show_featured_image’]) ? $instance[‘show_featured_image’] : false;

    $apply_content_filters = isset($instance[‘apply_content_filters’]) ? $instance[‘apply_content_filters’] : false;

    $content_post = get_post($custom_post_id);

    $post_status = get_post_status($custom_post_id);

    $content = $content_post->post_content;

    if ( $post_status == “publish” ) {

    // Display custom widget frontend

    if ( $located = locate_template( ‘custom-post-widget.php’ ) ) {

    require $located;

    return;

    }

    if ( !$apply_content_filters ) { // Don’t apply the content filter if checkbox selected

    $content = apply_filters( ‘the_content’, $content);

    }

    echo $before_widget;

    if ( $show_custom_post_title ) {

    echo $before_title . apply_filters( ‘widget_title’,$content_post->post_title) . $after_title; // This is the line that displays the title (only if show title is set)

    }

    if ( $show_featured_image ) {

    echo get_the_post_thumbnail( $content_post -> ID );

    }

    echo do_shortcode( $content ); // This is where the actual content of the custom post is being displayed

    echo $after_widget;

    }`

    Feel free to incorporate this into your plugin. Many thanks for creating it.

    Tom

    https://www.ads-software.com/plugins/custom-post-widget/

Viewing 1 replies (of 1 total)
  • Plugin Author Johan van der Wijk

    (@vanderwijk)

    Hi Tom,

    Thanks for the excellent suggestion, I have incorporated your code in V 2.7.2 of the plugin. The update should be available soon.

Viewing 1 replies (of 1 total)
  • The topic ‘Change Request – Only display Published posts.’ is closed to new replies.