Manage include_children in TOC category
-
Hi,
I was working with this plugin and noticed that [yadawikitoc show_toc=”true” category=”{category}” order=”date”] doesn’t handle the include_children parameter. Since it’s a very small edit, I made the changes myself and wanted to share them with everyone—maybe someone will find it helpful.
All you need to do is locate the \yada-wiki\inc\functions-public.php file and replace the code from lines 107 to 194 with this:
function yada_wiki_toc_shortcode( $atts ) {
extract( shortcode_atts( array(
'show_toc' => '',
'category' => '',
'order' => '',
'include_children' => false,
), $atts ) );
$show_toc = sanitize_text_field($show_toc);
$category = sanitize_text_field($category);
$order = sanitize_text_field($order);
$include_children = sanitize_text_field($include_children);
return get_yada_wiki_toc( $show_toc, $category, $order, $include_children );
}
//output toc
function get_yada_wiki_toc( $show_toc, $category, $order, $include_children ){
$show_toc = trim($show_toc);
$category = trim($category);
$order = trim($order);
$order_direction = "ASC";
if($category != "") {
// Output page title to all in the category
if($order == "") {
$order = "title";
} else if ($order == "datedesc") {
$order = "date";
$order_direction = "DESC";
}
$args = array(
'posts_per_page' => -1,
'offset' => 0,
'post_type' => 'yada_wiki',
'tax_query' => array(
array(
'taxonomy' => 'wiki_cats',
'field' => 'name',
'terms' => $category,
'include_children' => $include_children
),
),
'orderby' => $order,
'order' => $order_direction,
'post_status' => 'publish'
);
$cat_list = get_posts( $args );
$cat_output = '<ul class="wiki-cat-list">';
foreach ( $cat_list as $item ) {
$cat_output = $cat_output . '<li class="wiki-cat-item"><a class="wiki-cat-link" href="' . esc_url(get_post_permalink($item->ID)) . '">'.$item->post_title.'</a></li>';
}
$cat_output = $cat_output . '</ul>';
return $cat_output;
}
else if($show_toc == true) {
$the_toc = get_posts(
array(
'post_type' => 'yada_wiki',
'title' => 'TOC',
'post_status' => 'all',
'numberposts' => 1,
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
'orderby' => 'post_date ID',
'order' => 'ASC',
)
);
if($the_toc) { $the_toc=$the_toc[0]; }
if (! isset($the_toc) ) {
return __('A wiki article with the title of TOC was not found.', 'yada_wiki_domain');
}
else {
$toc_status = get_post_status( $the_toc );
if( $toc_status == "publish" ) {
$has_content = $the_toc->post_content;
if ($has_content) {
$the_content = apply_filters( 'the_content', $the_toc->post_content );
return $the_content;
} else {
return __('The TOC has no content.', 'yada_wiki_domain');
}
} else {
return __('The TOC has not been published.', 'yada_wiki_domain');
}
}
}
}Now, you can add “include_children=true” to your shortcode like this: [yadawikitoc show_toc=”true” category=”{category}” order=”date” include_children=true].
Thank you!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- You must be logged in to reply to this topic.