#2 Jun 17, 2017 04:37
- tableofcontent_plugin.zip (3.8 KB)
RenderItemAsHtml function, here:
$params['data'] = "<div id='" . $content_id . "'>" . $params['data'] . "</div>" . $script;
However, there is a built-in function that splits up the content of the post into different parts and also make a tags balance on each of those parts here: https://github.com/b2evolution/b2evolution/blob/release/6.8.x/inc/items/model/_item.class.php#L2126. So, the closing
</div> of your custom wrapper ends up right before of the "more" link, which is what b2evolution is considering as the first part of the post (teaser).
I think this behaviour is correct. So, you can make your code to depend on core ids and classes instead of depend on a custom generated id. I mean, if you replace the line:
$content_id = $this->random_str(5);
with this other:
$content_id = 'item_'.(isset($Item->ID)?$Item->ID:'').' .evo_post__full_text';
the plugin will work correctly (well, at least in the couple of quick tests I made :D)
That will make the first line of code I copied above useless, so you can replace it with:
$params['data'] .= $script;
Hi @mgsolipa ,
It's really cool and perfect solution to my problem, I have re-upload the code zip.Thanks a lot.
Fixed code zip
Do you have a Github account? You can share the code using it. If so, I can upload the code and give you full control of the repository. However, it's better if you upload it on your own, because it's your code ;)
Do you want for us to include the plugin here: http://plugins.b2evolution.net/ ?
I am very glad to share this plugin in http://plugins.b2evolution.net/ for anyone who wants to use. The code has made a lot of changes, also replace the previous JS file, so use the new one.
Also I create a github https://github.com/hhren1984/tableofcontents_plugin.git , but not much clearly how to use it at the moment, I will study.
Now a new problem, I try to add a selection of order list or unordered list for user choose, but it is only in effect at first setting, then unless reinstall it won't go into effect. Is there a way to make it work every time?
@haharen your list style setting works as expected. Maybe you can't see changes being applied because of the pre-render items cache. Almost all the render plugins output (depending on their rendering mode) is generated and saved into a cache each time we save the post. This way, there is no need to re-generate the content of the post each time it's displayed.
This is the case with your plugin, so after a settings change in your plugin, you have two options: 1) go the posts and save them again. 2) Force this massively by going to System > Maintenance > Clear pre-rendered item cache (DB)
 You could dig deeper into the rendering mode of the plugins explained here: http://b2evolution.net/man/plugin-apply-rendering
Now I am clear. Thanks for the complete explanat, also I will continue to improve this plugin.
Form is loading...