Tagged: table of contents, Widget
-
AuthorPosts
-
October 20, 2018 at 12:31 am #1024241
Hi,
I love the style of the new “Table of contents widget” in v4.5.
How can I show it on top of the content of a post or a page, not in the sidebar?
Thanks.
October 22, 2018 at 11:49 pm #1025178Hey Gitte,
You can use ALB, load a sidebar inside and load the specific widget :)
Let us know if you need further help.
Best regards,
BasilisOctober 23, 2018 at 11:42 am #1025354I would never ever use the ALB for posts! Whenever you switch the theme one day, you have tons of shortcodes in your posts you need to clean up manually!
So how can I add ENFOLD’s TOC widget in the top of a post’s or page’s content?
Perhaps a snippet for the loop-index?
Or better a functions.php snippet?October 23, 2018 at 11:23 pm #1025691Hi,
Unfortunately, it would require quite some time and customization of the theme to achieve this, so I am sorry to tell you that this is not covered by our support. However, if it’s really important for you to get this done, you can always hire a freelancer to do the job for you :)
Best regards,
BasilisOctober 24, 2018 at 3:45 pm #1025944Where is the Avia Toc code located (in which file), so that I could create a shortcode from it – and how please?
This is possible, because we had this several times here in the forum concerning other ENFOLD features.Thanks.
October 29, 2018 at 8:04 am #1027394Hi,
This is possible but you have to modify the single.php file.
Add this code:
$args = array ( 'name' => 'Displayed Everywhere', 'id' => 'av_everywhere', 'description' => '', 'class' => '', 'before_widget' => '<section id="avia_auto_toc-2" class="widget clearfix avia_auto_toc">', 'after_widget' => '<span class="seperator extralight-border"></span></section>', 'before_title' => '', 'after_title' => '', 'widget_id' => 'avia_auto_toc_custom', 'widget_name' => 'Enfold Child Table of Contents', ); $instance = array ( 'title' => 'Toc', 'exclude' => '', 'style' => '', 'level' => 'h1', 'single_only' => 1, 'indent' => 1, 'smoothscroll' => 1, ); $toc = new avia_auto_toc; $toc->widget($args, $instance);
Above line 41:
get_template_part( 'includes/loop', 'index' );
Yes, you can create a custom shortcode from that.
Best regards,
IsmaelOctober 29, 2018 at 3:54 pm #1027603– Thanks a lot, Ismael, it works fine. Could you please tell me, where to add this snippet in – I guess – the loop-index.php (?), so that the TOC is after the featured image and after the post title, but before the content?
Currently with you snippet, the TOC is above everything (above the featured image resp. post title).
Is the snippet then valid as you added it above for the loop-index, too, or does it need a modification for that file?– And could you please give me a hint, how to make a shortcode out of it please?
Thank you.October 30, 2018 at 6:15 am #1027872Hi,
You can move that code in the includes > loop-index.php file where the post elements reside, right about line 262 where the title is.
echo $title;
– And could you please give me a hint, how to make a shortcode out of it please?
The shortcode:
add_shortcode('avs_toc', 'avs_toc_function'); function avs_toc_function() { $args = array ( 'name' => 'Displayed Everywhere', 'id' => 'av_everywhere', 'description' => '', 'class' => '', 'before_widget' => '<section id="avia_auto_toc-2" class="widget clearfix avia_auto_toc">', 'after_widget' => '<span class="seperator extralight-border"></span></section>', 'before_title' => '', 'after_title' => '', 'widget_id' => 'avia_auto_toc_custom', 'widget_name' => 'Enfold Child Table of Contents', ); $instance = array ( 'title' => 'Toc', 'exclude' => '', 'style' => '', 'level' => 'h1', 'single_only' => 1, 'indent' => 1, 'smoothscroll' => 1, ); $toc = new avia_auto_toc; return $toc->widget($args, $instance); }
You can then use this code to render the toc in the template file:
echo do_shortcode('[avs_toc]');
Or use it directly in the editor.
Best regards,
IsmaelOctober 30, 2018 at 3:16 pm #1028060Thank you, Ismael. Can I add your snippet for the shortcode exactly so for showing
[avs_toc]
in an ALB text block within a post or page manually?
I added your snippet
add_shortcode('avs_toc', 'avs_toc_function'); function avs_toc_function() { $args = array ( 'name' => 'Displayed Everywhere', 'id' => 'av_everywhere', 'description' => '', 'class' => '', 'before_widget' => '<section id="avia_auto_toc-2" class="widget clearfix avia_auto_toc">', 'after_widget' => '<span class="seperator extralight-border"></span></section>', 'before_title' => '', 'after_title' => '', 'widget_id' => 'avia_auto_toc_custom', 'widget_name' => 'Enfold Child Table of Contents', ); $instance = array ( 'title' => 'Toc', 'exclude' => '', 'style' => '', 'level' => 'h1', 'single_only' => 1, 'indent' => 1, 'smoothscroll' => 1, ); $toc = new avia_auto_toc; return $toc->widget($args, $instance); }
to my Code-Snippets plugin, where all snippets go, that normally go to the functions.php,
and then added the shortcode [avs_toc] to a text block ALB element in a page, but there is no output at all.Are there any changes to the snippet necessary?
Thanks.November 2, 2018 at 8:11 am #1029060Hi,
Yes, you can use that shortcode. And you have to set the “single_only” parameter from 1 to 0 if you want to use it on pages.
Best regards,
IsmaelAugust 27, 2019 at 3:48 pm #1131347I have a fresh new installation of the latest ENFOLD at my site and tried to add manually a TOC.
The only thing I did now is putting this snippet to my Code Snippets Plugin:
add_shortcode('avs_toc', 'avs_toc_function'); function avs_toc_function() { $args = array ( 'name' => 'Displayed Everywhere', 'id' => 'av_everywhere', 'description' => '', 'class' => '', 'before_widget' => '<section id="avia_auto_toc-2" class="widget clearfix avia_auto_toc">', 'after_widget' => '<span class="seperator extralight-border"></span></section>', 'before_title' => '', 'after_title' => '', 'widget_id' => 'avia_auto_toc_custom', 'widget_name' => 'Enfold Child Table of Contents', ); $instance = array ( 'title' => 'Toc', 'exclude' => '', 'style' => '', 'level' => 'h1', 'single_only' => 1, 'indent' => 1, 'smoothscroll' => 1, ); $toc = new avia_auto_toc; return $toc->widget($args, $instance); }
Then I added at the beginning of a post manually (I do not want it in every post!!!) this:
[avs_toc]
Note: I do not use the ALB for posts and I do not use the Gutenberg editor.
But nothing is shown – see screenshots below -, although there are h2, h3, h4 headlines in the post.
Is something wrong with the snippet for ENFOLD 4.5.7?
August 29, 2019 at 2:40 pm #1131885Hi,
Thank you for using Enfold.
Did you add it in a page? If so, try to set the ‘single_only’ parameter to 0. That should enable the widget for pages.
Best regards,
IsmaelAugust 30, 2019 at 11:39 am #1132283No, I added it in a post, not a page in this way, but I have overseen something ;-)
the TOC is added to the post but ABOVE the featured image, instead of below it:
This is at the beginning of a post:
[avs_toc] Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem.
Result:
How can I have the TOC really there, where I add the shortcode in a post?
Normally at the beginning of the actual content …—————————————————————————————
EDIT:
see private data for my test post at my test installation – here runs ENFOLD v4.6 and it is the same.- This reply was modified 5 years, 3 months ago by BeeCee. Reason: private data added
September 2, 2019 at 5:12 am #1132800Hi,
Thank you for the update.
This works fine on our own installation. Are you using the special heading elements?UPDATE: We set the ‘single_only’ parameter to 0. It works now.
Best regards,
IsmaelSeptember 2, 2019 at 2:31 pm #1133001Thanks, but I don’t see that it works, sorry, the Table of Content is still above the featured image of the post, instead above the content of the post:
Please look above the featured image, there is the TOC and not right above the content, where it belongs and where the shortcode has been added.
I added the shortcode within the post editor, where it belongs: the TOC should be at the beginning of this post’s content/text:September 3, 2019 at 3:55 am #1133169Hi,
Thank you for the update.
Yeah, that’s odd. We can’t find the script that’s doing that. What you can do is prepend it back to the “entry-content” container on page load using javascript.
// https://api.jquery.com/appendTo/
Best regards,
IsmaelSeptember 3, 2019 at 11:57 am #1133321Thanks, but I am not a coder, I don’t understand what you mean and what I have to do.
Isn’t it possible to make changes to your snippet – see private data below?
September 6, 2019 at 8:05 am #1134789Hi,
We would like to add the script, but the Appearance > Editor panel is not accessible. Please enable it or post the FTP details in the private field. You can try this script in the functions.php file for the meantime.
add_action('wp_footer', function() { ?> <script> (function($) { $(document).ready(function() { $('.av_toc_container').prependTo('.entry-content'); }); })(jQuery); </script> <?php });
Best regards,
Ismael -
AuthorPosts
- You must be logged in to reply to this topic.