• Resolved benergize

    (@bensaysstuff)


    Hello,

    Writing to request the following feature:

    The ability to add parameters to the shortcode that will replace text in the content. Like the following:

    
      /* The Content Block content: */
      Please enjoy this {{arg0}} coupon.
    
    
      /* The post where the shortcode is used: */
      [content_block slug=example-block arg0="50% off"]
    
    
      /* The above two code blocks would then output: */
      Please enjoy this 50% off coupon.
    

    Here is code for a simple implementation of this feature–there is certainly a more elegant approach to this, but this is an example. This currently lives in the custom_post_widget_shortcode function in the foreach( $content_post as $post ) loop in post-widget.php.

    
      for($i = 0; $i < 12; $i++) {
        if($atts['arg' . $i]) {
          $content = str_ireplace("{{arg" . $i . "}}", $atts['arg' . $i], $content);
        }
      }
    

    Let me know your thoughts. Thank you for your plugin!

    • This topic was modified 3 years, 10 months ago by benergize.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter benergize

    (@bensaysstuff)

    A slightly more elegant approach, which allows for arbitrary parameter names:

    
    foreach($atts as $att=>$val) { 
      if($att != 'id') { $content = preg_replace("/\{\{ *" . $att . " *\}\}/i", $val, $content); }
    }
    
    Plugin Author Johan van der Wijk

    (@vanderwijk)

    Thanks for your suggestion, for the widgets my plugin already supports custom templates and I am thinking about adding this also to the shortcode. Would that help you?

    Thread Starter benergize

    (@bensaysstuff)

    Hi Johan,

    Thanks for the response. Indeed I am referring to shortcodes–sorry if that wasn’t clear. That would be a helpful feature, yes.

    Plugin Author Johan van der Wijk

    (@vanderwijk)

    Hi Ben,

    I have now added the option for using custom templates for the content blocks that are included on the page with the shortcode.

    The new version has not been released yet, but you can test it by installing it from the Github repository: https://github.com/vanderwijk/custom-post-widget/archive/master.zip

    So now you can create your own template for the shortcode and place this in your theme folder. Then call this template in your shortcode like in this example:

    [content_block id=5 template="my-shortcode-template.php"]

    You can find an example template in the example-templates folder of the plugin zipfile.

    Could you please try this and let me know if this helps you?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Feature Request: Content Parameters/Arguments’ is closed to new replies.