• Resolved Global

    (@global_1981)


    Hi Johan,
    Excellent plugin!

    I have a feature suggestion – check for a matching template part in the theme folder before outputting/displaying the content block.

    For example with the code below, if a user had a content block with the title About Us,
    they could also have a template part called block-aboutus.php in their theme folder that would handle the output:

    Add to post-widget.php, line 83
    // Look for template before default output
    $title = str_replace(array(' ','_','-'), '', strtolower($content_post->post_title) );
    if (locate_template("block-{$title}.php")) {
    echo get_template_part('block', $title);
    return;
    }

    This will allow the plugin to work really well with something like Advanced Custom Fields – You can effectively have Advanced Custom Fields (ACF) for Sidebar Widgets when used in conjunction with your plugin. Let me know your thoughts! I want to actually write a tutorial on my blog bcooling.com.au/blog about using ACF + Custom Post Widget for this purpose.

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Global

    (@global_1981)

    Revised code (for post-wiget.php:83) to include template tags in template parts:

    $title = str_replace(array(' ','_','-'), '', strtolower($content_post->post_title) );
    if (locate_template("block-{$title}.php")) {
    global $post;
    $post = $content_post;
    setup_postdata($post);
    echo get_template_part('block', $title);
    wp_reset_postdata();
    return;
    }

    Thread Starter Global

    (@global_1981)

    Sorry for the many posts, but this fixes the issue of returning to early:

    $title = str_replace(array(' ','_','-'), '', strtolower($content_post->post_title) );
    if (locate_template("block-{$title}.php")) {
    global $post;
    $post = $content_post;
    setup_postdata($post);
    echo get_template_part('block', $title);
    wp_reset_postdata();
    }
    else {
    echo do_shortcode($content); // This is where the actual content of the custom post is being displayed
    }

    Plugin Author Johan van der Wijk

    (@vanderwijk)

    Hi global_1981,

    This sounds interesting, but I am not sure if I correctly understand what you are trying to achieve.

    Wouldn’t insering the shortcode directly to the template be a solution? For example: <?php echo do_shortcode('[content_block id=18]'); ?>

    Thread Starter Global

    (@global_1981)

    Hi Johan,

    Using the shortcode would work for if the content block only used the editor and title fields. But what if you wanted they used the featured image?

    My suggestion gives the user an advanced option to control the output of the content block, in particular the ability to display non-title and non-editor fields such as:
    ? Featured Image
    ? Other meta data associated with the content block such as date, author.
    ? Custom Fields (That is why I mentioned the excellent Advanced Custom Fields)

    In fact I have ur plugin (with my suggestion) + Advanced Custom Fields working in a production environment at the moment which allows the user to add however many social media icons they want (with links) to a content block that appears in the sidebar.

    Plugin Author Johan van der Wijk

    (@vanderwijk)

    I have created a new version of the plugin which now also allows you to show the featured image in a widget: https://downloads.www.ads-software.com/plugin/custom-post-widget.zip

    I’ll still have to update the shortcode functionality to display the featured image, but it seems that the shortcode is not being used very often anyway.

    The method of displaying the content block that you propose might be a bit too advanced for most users and increase my support workload. I therefore don’t think I will incorporate this in the plugin, but thanks for suggesting this feature and providing the sample code.

    Thread Starter Global

    (@global_1981)

    I understand Johan, thanks for the great work on the plugin…

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Feature Suggestion’ is closed to new replies.