我有以下几点。当我调用它时,在页面中,页面中的内容总是在插件之后,而不是之前。能帮点忙吗?
<?php
function category_has_children($term_id)
{
$children = get_term_children($term_id, "category");
if (is_array($children)) {
return $children;
} else {
return false;
}
}
// Add Shortcode
function dataservices_category($atts)
{
// Attributes
extract(shortcode_atts(array(
\'id\' => \'\'
), $atts));
// Code
if (isset($id)) {
$categories = get_categories(\'child_of=\' . $id);
foreach ($categories as $category) {
if ($category->parent != $id) {
echo \'<div style="margin-left:50px;">\';
echo \'<h4>\' . $category->name . \'</h4>\';
} else {
echo \'<h3>\' . $category->name . \'</h3>\';
}
if (category_has_children($category->term_id) == false):
echo \'<ul>\';
foreach (get_posts(\'cat=\' . $category->term_id) as $post) {
setup_postdata($post);
echo \'<li><a href="\' . get_permalink($post->ID) . \'">\' . get_the_title($post->ID) . \'</a> </li>\';
}
echo \'</ul>\';
endif;
if ($category->parent != $id) {
echo \'</div>\';
}
}
}
}
add_shortcode(\'dataservices\', \'dataservices_category\');
?>