I made a post template using meta box(custom field). If I put data into metabox, the template part (contents with h2, h3, p) shows up at the bottom of post (not on post edit page). However, every TOC plugins use "revisions" to check if there is h2 or h3 like this code.
public function widget( $args, $instance ) {
global $ht_kb_toc_tools, $wp_query;
if( ! is_singular() )
return;
if ( ! isset( $wp_query ) ) {
return;
}
if( is_a($ht_kb_toc_tools, 'HT_KB_TOC_Tools') ){
if( $ht_kb_toc_tools->ht_block_toc_detected && apply_filters('ht_kb_toc_disable_on_ht_block_toc', true ) ){
//early exit if ht-block-toc detected
return;
}
}
extract( $args, EXTR_SKIP );
$instance = wp_parse_args( $instance, $this->defaults );
//$post = get_post( $wp_query->post->ID );
$post = get_post();
if( is_preview() ){
//get the post revisions
$post_revisions = ( wp_get_post_revisions( $post ) );
if ( !empty( $post_revisions ) ) {
//get the latest revision - this should be the current preview
$post = current( $post_revisions );
}
}
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
if(is_a($ht_kb_toc_tools, 'HT_KB_TOC_Tools')){
//extract headings
$headings = $ht_kb_toc_tools->ht_kb_toc_extract_headings( do_shortcode( $post->post_content ), true );
//don't output widget if no headings are in content
if(empty($headings))
return;
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
?>
<nav id="navtoc" role="navigation">
<?php
//display items
$ht_kb_toc_tools->ht_kb_display_items();
?>
</nav>
<?php
}
echo $after_widget;
} // end widget
Is there another way to check h2 or h3 beside checking revision? or is there a way that shows my metabox data show on post edit page? Thanks.