I'm by no means a PHP guru and have been given the task of updating a WordPress site. I've managed to get my php-includer plugin to work so that I can use a shortcode within the content area which the editor can then reference a stand-alone file which will then get injected into the main page.
The code I'm using is this:
<?php
function PHP_Include($params - array()) {
extract(shortcode_atts(array(
'file' => 'default'
), $params));
ob_start();
include(get_stylesheet_directory() . "/inc/$file.php");
return ob_get_clean();
}
add_shortcode('phpinclude', 'PHP_Include');
?>
I've saved this as a plugin and then using [phpinclude file='testfile'] in the content on a blog post. While the external testfile.php is included into the content, what I am after is a way of targeting parameters.
So for example, if the page held 4 images, I could specify in a parameter how many I would want to display. The editor could then add the following code [phpinclude file='testfile' images=2]. This would then display only 2 images instead of the default 4 images.
Does anyone know of a way to do this with the code I've shown above or point me in the right direction?