Recent Topics

Table Of Content Plugin

started by on Jun 17, 2017 – Last touched: Jun 18, 2017

Jun 17, 2017 04:35    

Please see the screenshot at second floor.
BUT I met a problem, this plugin can't use the [ teaserbreak ] tag, because this tag would cut the content also make the table of content incompletly display.How to deal with it ???

Jun 17, 2017 11:54

Hi @haharen,

The problem is that your javascript code depends on a wrapper that you create in your 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;

Regards!

Jun 17, 2017 13:22

Hi @mgsolipa ,
It's really cool and perfect solution to my problem, I have re-upload the code zip.Thanks a lot.

Jun 17, 2017 19:44

@haharen Good!

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/ ?

Jun 18, 2017 09:52

@mgsolipa
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?

Jun 18, 2017 15:04

@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[1]) 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)

[1] You could dig deeper into the rendering mode of the plugins explained here: http://b2evolution.net/man/plugin-apply-rendering

Jun 18, 2017 15:41

@mgsolipa
Now I am clear. Thanks for the complete explanat, also I will continue to improve this plugin.


Form is loading...

free blog software – This forum is powered by b2evolution CMS, a complete engine for your website.