[ad_1]
[ad_2]
I've been looking for a way to add scripting inside the page to be able to format without writing PHP code. I'm a PODS user and can do most of the formatting with that, but I'd like to be able to do the math functions and some of the branching inside the page. I'd like to keep people away from writing PHP code and keep their scripts confined to posts.
You can use Smarty in WordPress posts by creating a custom shortcode that processes Smarty templates. Set up the Smarty library on your server, create a shortcode to handle Smarty scripting, and use it within your posts like this:
“`php
function smarty_template_shortcode($atts, $content = null) {
require_once(‘path/to/smarty/libs/Smarty.class.php’);
$smarty = new Smarty();
$smarty->assign(‘content’, $content);
return $smarty->fetch(‘string:’ . $content);
}
add_shortcode(‘smarty’, ‘smarty_template_shortcode’);
“`
Use `[smarty]…[/smarty]` in your posts for formatting and logic without writing PHP directly.