just starting with php. including a list, using a shortcode. Issue is that the included list appears at the top of the wrapper in the DOM instead of where i'm placing it in the html editor: the function (which i put in functions.php) is:
function objectlist() {
include("objects1.php");
}
add_shortcode('get_my_objects', 'objectlist');
html (wordpress html view):
<div class="listGenCont">
<div class="objectList1">
[get_my_objects]
</div></div>
but the output ends up being:
<ul class="thingsathome"> **this is the included list**
<div class="listGenCont">
<div class="actressList">**this is where i want it**</div>
</div>
wonder why this happens and how to fix it
Then check out this code snippet (credits):
function include_file($atts) {
//check the input and override the default filepath NULL
//if filepath was specified
extract(shortcode_atts(array('filepath' => 'NULL'), $atts));
//check if the filepath was specified and if the file exists
if ($filepath!='NULL' && file_exists(TEMPLATEPATH.$filepath)) {
//turno on output buffering to capture script output
ob_start();
//include the specified file
include(TEMPLATEPATH.$filepath);
//assign the file output to $content variable and clean buffer
$content = ob_get_clean();
return $content;
}
}
//register the Shortcode handler
add_shortcode('include', 'include_file');
When you use plain include it gets evaluated at the start of the WordPress request. This example uses capturing of the output biffer to prevent this.