Table of Contents Plus帮助 - wordpress文档

可以为长页面(和自定义帖子类型)自动创建特定于上下文的索引或目录(TOC)。该插件不仅仅是目录插件,它还可以输出列出整个网站上的页面和/或类别的站点地图

一个功能强大但用户友好的插件,可以为长页面(和自定义帖子类型)自动创建特定于上下文的索引或目录(TOC)。该插件不仅仅是目录插件,它还可以输出列出整个网站上的页面和/或类别的站点地图。

Table of Contents Plus帮助 - wordpress文档-Npcink
Table of Contents Plus帮助 - wordpress文档-Npcink

Table of Contents Plus - 给网站中的文章/页面添加内容目录的wordpress插件

一个简单的文章目录,既可以方便读者阅读长篇文章,让他们快速找到自己想要阅读的内容;又有利于SEO,有利于Google,百度等搜索引擎理清文章的内容结构

描述

目录是从头开始构建的,并且考虑到了Wikipedia,默认情况下,目录出现在页面的第一个标题之前。这使作者可以插入可以概述或介绍页面其余部分的导入内容。它还使用了独特的编号方案,不会因跨主题的CSS差异而丢失。

该插件是内容丰富站点(例如面向内容管理系统的配置)的绝佳伴侣。也就是说,博客作者在编写较长的结构化文章时也具有相同的好处。了解Google如何使用此索引为您的内容提供“跳转到”链接。

包括一个管理选项面板,您可以在其中自定义设置(例如显示位置),定义显示索引之前的最小标题数,其他外观等。对于高级用户,请扩展高级选项以进一步调整其行为-例如:排除不希望出现的航向级别,例如h5和h6;禁用包含的CSS文件的输出;调整顶部偏移量等等。使用短代码,您可以覆盖默认行为,例如特定页面上的特殊排除,甚至完全隐藏目录。

倾向于在侧边栏中包含索引?转到外观>小部件,然后将TOC +拖到所需的侧边栏和位置。

支持自定义帖子类型,但是,仅当the_content()自定义帖子类型使用自动插入功能时,自动插入才有效。每种帖子类型都会出现在选项面板中,因此请启用所需的帖子。

翻译

  • 澳大利亚英语(默认)
  • 丹麦文- 库普努
  • 荷兰人– 蕾妮
  • 法语– Jean-Michel Duriez
  • 德语– 本
  • 希腊文– Dimitrios Kaisaris
  • 希伯来语- 阿雷拉尔
  • 日语– シカマル
  • 波兰语- 雅库布
  • 简体中文– Jason
  • 斯洛伐克语-Boris Gereg
  • 乌克兰语– 迈克尔·尤纳特

安装/升级

通过从插件添加菜单或直接从WordPress插件存储库中搜索Table of Contents Plus来安装插件。

没有特别的升级说明(woohoo!)。使用最新的覆盖现有文件夹或使用插件菜单中的简化方法。您的选择不会丢失。

救命

最简单的方法

对于不耐烦的人,您要做的就是启用插件。

该插件将应用默认设置,并在具有四个或更多标题的页面上第一个标题(不是帖子,也不是自定义帖子类型)之前生成目录。

不需要简码。

我的目录在哪里?

  1. 在大多数情况下,帖子,页面或自定义帖子类型的标题少于最小标题数。默认情况下,此设置为4,因此请确保内容中至少包含四个标题。如果要更改此值,可以在“主要选项”>“显示时间”下找到它。
  2. 您的内容类型是否启用了自动插入?默认情况下,仅启用页面。
  3. 在内容中找到了什么吗?这将禁用当前帖子,页面或自定义帖子类型的索引。
  4. 如果您使用的是TOC +小部件,请检查是否启用了“仅在侧栏中显示目录”,因为这会将其显示限制为仅在侧栏中。您可以进入外观>小部件进行检查。
  5. 您可能将生成限制为URL路径匹配。该设置可以在“主选项”下的高级部分中找到。

如何阻止目录显示在单个页面上?

将以下内容放置在页面上的任何位置以隐藏目录。这被称为简码,适用于使用the_content()的帖子,页面和自定义帖子类型

我已将包裹设置为左或右,但标题未包裹目录

通常在主题附近的标题中或标题附近有CSS清除指令时会发生这种情况(二十一个和二十二个是这两个主题)。该指令告诉用户代理重置以前的包装规范。

您可以调整主题的CSS或尝试将目录位置移到页面顶部。如果您没有构建主题,则强烈建议您尝试更改CSS时尝试使用Custom CSS插件

尝试添加以下CSS,以允许在目录周围进行换行:


h1, h2, h3, h4, h5, h6 { clear: none; }

如何在目录标题中包含页面名称?

当页面标题根据您正在查看的页面而变化时,您可以使用以下特殊变量将页面标题自动插入目录标题中:

%PAGE_NAME%

您可以按原样使用它,也可以在变量的两边放置文本。

例如:如果您的页面被命名为Great Expectations,并且目录标题设置为Contents for%PAGE_NAME%,则最终标题将显示Contents for Great Expectations

我的网站有100页,但我只希望目录出现在其中的10页上

您可以输入90页,但那并不有趣……所以请尝试以下操作:

  1. 转到“设置”>“ TOC +”,然后禁用页面(或正在使用的内容类型)的自动插入选项。
  2. 添加到需要它们的10页上。请注意,目录将出现在您放置短代码的位置。

或者,如果您要全部包含索引的页面都属于站点的特定部分(例如/ doc /),则也可以尝试使用限制路径选项。

我想忽略某些标题

如果您想忽略某些标题,请使用“排除标题”选项。用管道将多个标题分开|。使用星号*作为通配符来匹配其他文本。请注意,这不区分大小写。一些示例包括:

  • Fruit*忽略以Fruit开头的标题
  • *Fruit Diet*忽略标题中某处的“ 水果饮食 ”标题
  • Apple Tree|Oranges|Yellow Bananas忽略完全是苹果树橘子黄香蕉的标题

侧边栏可以有目录吗?

使用TOC +小部件并将其拖动到所需位置。如果您希望目录仅显示在侧边栏中,请确保在窗口小部件中打勾该选项。

与Wikipedia不同,我希望所有锚点都小写并使用连字符而不是下划线

有两个选项可让您调整大小写和连字符。如果您仍然需要更多,可以通过连接到toc_url_anchor_target过滤器上进行按摩。有关示例,请参见开发人员部分。

我想加入一个站点地图

  1. 为您的站点地图创建一个页面(如果已有页面,请改用该页面)。
  2. 添加到您的页面并保存。

上面是集成列出所有页面和类别的站点地图的最简单示例。您可以在“设置”>“ TOC +”下自定义站点地图选项,或通过以下与站点地图相关的短代码查看一些更高级的用法。

您还可以使用文本小部件并粘贴任何站点地图简码来合并站点地图。

该站点地图使用的奇怪字体与该站点的其余部分不同

没有为站点地图创建任何其他样式,而是继承了您在添加简码时使用的任何样式。如果您复制并粘贴,则可能还复制了它周围的“代码”标签,因此,请删除它们。

在大多数情况下,请尝试将简码放在自己的行中,方括号之前或之后都不要包含任何内容。

简码

该插件被设计为尽可能无缝且无痛苦,并且不需要您插入操作的简码。但是,使用简码可以完全控制目录在页面中的位置。以下简短代码可与此插件一起使用。

如果下面的短代码省略了参数,它们将退回到您在“设置”>“ TOC +”下定义的设置。

短代码描述属性
[目录]使您可以在首选位置生成目录。对于只需要少量页面上的目录的网站也很有用。标签:文字,目录标题no_label:true / false,显示或隐藏标题包装:文字,“左”或“右”heading_levels:数字,这使您可以选择要包含在目录中的标题级别。用逗号分隔多个级别。示例:包括标题3、4和5,但排除其他带有heading_levels="3,4,5"exclude:文本,输入要排除的标题。用管道将多个标题分开|。使用星号*作为通配符来匹配其他文本。您也可以使用正则表达式进行更高级的匹配。class:文本,输入要添加到容器的CSS类。用空格分隔多个类。
允许您禁用当前帖子,页面或自定义帖子类型的目录。 
[网站地图]生成您网站的所有页面和类别的列表。您可以在任何帖子,页面甚至是文本小部件中使用它。 
使您仅打印页面列表。标题:1到6之间的数字,定义要使用的html标题标签:文本,列表标题no_label:true / false,显示或隐藏列表标题排除:您要排除的页面或类别的IDexclude_tree:您要排除的页面或类别的ID,包括其所有后代
类似,但类别不同。 

a

b

c

m

p

s

t

w

这使您可以打印出网站上所有已发布文章的索引。默认情况下,帖子按字母顺序列出,并按首字母分组。每个部分,字母和列表都有CSS类,可让您自定义外观。顺序:文字,ASC或DESCorderby:文本,常用的选项包括“标题”,“日期”,“ ID”和“ rand”。有关列表,请参见WP_Querysplit:true / false(默认为true),设置为false时不按首字母分隔列表。

对于开发人员

如何自定义锚点?

如果您仍然对锚不满意,可以通过连接到toc_url_anchor_target过滤器的自定义函数来修改锚以适合您的需求。例如,将以下代码片段放入您的functions.php文件中,以将所有锚点转换为大写字母。

function my_custom_anchor( $anchor )
{
	return strtoupper( $anchor );
}
add_filter( 'toc_url_anchor_target', 'my_custom_anchor' );

Contents Plus

1,136 COMMENTS

A powerful yet user friendly plugin that automatically creates a context specific index or table of contents (TOC) for long pages (and custom post types). More than just a table of contents plugin, this plugin can also output a sitemap listing pages and/or categories across your entire site.

Contents [hide]

Description

Built from the ground up and with Wikipedia in mind, the table of contents by default appears before the first heading on a page. This allows the author to insert lead-in content that may summarise or introduce the rest of the page. It also uses a unique numbering scheme that doesn’t get lost through CSS differences across themes.

This plugin is a great companion for content rich sites such as content management system oriented configurations. That said, bloggers also have the same benefits when writing long structured articles. Discover how Google uses this index to provide ‘Jump To’ links to your content.

Includes an administration options panel where you can customise settings like display position, define the minimum number of headings before an index is displayed, other appearance, and more. For power users, expand the advanced options to further tweak its behaviour – eg: exclude undesired heading levels like h5 and h6 from being included; disable the output of the included CSS file; adjust the top offset and more. Using shortcodes, you can override default behaviour such as special exclusions on a specific page or even to hide the table of contents altogether.

Prefer to include the index in the sidebar? Go to Appearance > Widgets and drag the TOC+ to your desired sidebar and position.

Custom post types are supported, however, auto insertion works only when the_content() has been used by the custom post type. Each post type will appear in the options panel, so enable the ones you want.

Translations

Translations are more than welcome. The translation file can be found in the languages folder of the plugin, or online in the WordPress repository.

If you have any advice in making it easier to translate, please let me know.

Screenshots

An example of the table of contents, positioned at the top, right aligned, and a width of 275pxAn example of the sitemap_pages shortcodeAn example of the sitemap_posts shortcode
The options panel found in Settings > TOC+Some advanced optionsThe sitemap tab

Install / upgrade

Install the plugin by searching for Table of Contents Plus from the plugin add menu, or directly from the WordPress plugins repository.

There are no special upgrade instructions (woohoo!). Overwrite your existing folder with the latest or use the streamlined approach in the plugin menu. Your options will not be lost.

Help

The simplest approach

For the impatient, all you have to do is enable the plugin.

The plugin will apply default settings and produce the table of contents before the first heading on pages (not posts, nor custom post types) with four or more headings.

No shortcodes are needed.

Where’s my table of contents?

  1. In most cases, the post, page or custom post type has less than the minimum number of headings. By default, this is set to four so make sure you have at least four headings within your content. If you want to change this value, you can find it under ‘Main Options’ > ‘Show when’.
  2. Is auto insertion enabled for your content type? By default, only pages are enabled.
  3. Have you got  somewhere within the content? This will disable the index for the current post, page or custom post type.
  4. If you are using the TOC+ widget, check if you have the “Show the table of contents only in the sidebar” enabled as this will limit its display to only the sidebar. You can check by going into Appearance > Widgets.
  5. You may have restricted generation to a URL path match. The setting can be found in the advanced section under Main Options.

How do I stop the table of contents from appearing on a single page?

Place the following  anywhere on the page to suppress the table of contents. This is known as a shortcode and works for posts, pages and custom post types that make use of the_content()

I’ve set wrapping to left or right but the headings don’t wrap around the table of contents

This normally occurs when there is a CSS clear directive in or around the heading originating from the theme (Twenty Eleven and Twenty Twelve are two themes which do this). This directive tells the user agent to reset the previous wrapping specifications.

You can adjust your theme’s CSS or try moving the table of contents position to the top of the page. If you didn’t build your theme, I’d highly suggest you try the Custom CSS plugin if you wish to make CSS changes.

Try adding the following CSS to allow the wrapping to occur around the table of contents:


h1, h2, h3, h4, h5, h6 { clear: none; }

How do I include the name of the page in the table of contents title?

As the title of the page changes depending on the page you’re viewing, you can use the following special variable to automatically insert the title of the page into the table of contents heading:

%PAGE_NAME%

You can use it as is or place text either side of the variable.

As an example: if your page is named Great Expectations and your table of contents title is set to Contents for %PAGE_NAME%, the final title would read Contents for Great Expectations

My site has 100 pages but I only want the table of contents to appear on 10 of them

You could put  on the 90 pages but that wouldn’t be fun… so try the following:

  1. Go to Settings > TOC+ and disable the auto insertion option for pages (or the content type you’re working with).
  2. Add  onto the 10 pages that need them. Note that the table of contents will appear where you placed the shortcode.

Alternatively, you could also experiment with the restrict path option if the pages you want to include the index on all fall within a certain section of your site (eg /doc/).

I want to ignore certain headings

Use the ‘exclude headings’ option if you would like to ignore certain headings. Separate multiple headings with a pipe |. Use an asterisk * as a wildcard to match other text. Note that this is not case sensitive. Some examples include:

  • Fruit* ignore headings starting with Fruit
  • *Fruit Diet* ignore headings with Fruit Diet somewhere in the heading
  • Apple Tree|Oranges|Yellow Bananas ignore headings that are exactly Apple TreeOranges or Yellow Bananas

Can I have the table of contents in the sidebar?

Use the TOC+ widget and drag it into your desired position. If you want the table of contents to only be displayed in the sidebar, then make sure you tick that option in the widget.

Unlike Wikipedia, I want all my anchors to be lowercase and use hyphens rather than underscores

There are two options that allow you to adjust the casing and use of hyphens. If you still require more, you can massage it a little more by attaching into the toc_url_anchor_target filter. See the developers section for an example.

I would like to incorporate a sitemap

  1. Create a page for your sitemap (if you have an existing one, use that instead).
  2. Add  into your page and save.

The above is the simplest example of integrating a sitemap listing all pages and categories. You can customise the sitemap options under Settings > TOC+ or check out some of the more advanced uses with the sitemap related shortcodes below.

You could also incorporate a sitemap using a text widget and pasting any of the sitemap shortcodes.

The sitemap uses a strange font dissimilar to the rest of the site

No extra styles are created for the sitemap, instead it inherits any styles you used when adding the shortcode. If you copy and pasted, you probably also copied the ‘code’ tags surrounding it so remove them if this is the case.

In most cases, try to have the shortcode on its own line with nothing before or after the square brackets.

Shortcodes

The plugin was designed to be as seamless and painfree as possible and did not require you to insert a shortcode for operation. However, using the shortcode allows you to fully control the position of the table of contents within your page. The following shortcodes are available with this plugin.

When parameters are left out for the shortcodes below, they will fallback to the settings you defined under Settings > TOC+.

SHORTCODEDESCRIPTIONATTRIBUTES
Lets you generate the table of contents at the preferred position. Also useful for sites that only require a TOC on a small handful of pages.label: text, title of the table of contentsno_label: true/false, shows or hides the titlewrapping: text, either “left” or “right”heading_levels: numbers, this lets you select the heading levels you want included in the table of contents. Separate multiple levels with a comma. Example: include headings 3, 4 and 5 but exclude the others with heading_levels="3,4,5"exclude: text, enter headings to be excluded. Separate multiple headings with a pipe |. Use an asterisk * as a wildcard to match other text. You could also use regular expressions for more advanced matching.class: text, enter CSS classes to be added to the container. Separate multiple classes with a space.
Allows you to disable the table of contents for the current post, page, or custom post type. 
Produces a listing of all pages and categories for your site. You can use this on any post, page or even in a text widget. 
Lets you print out a listing of only pages.heading: number between 1 and 6, defines which html heading to uselabel: text, title of the listno_label: true/false, shows or hides the list headingexclude: IDs of the pages or categories you wish to excludeexclude_tree: ID of the page or category you wish to exclude including its all descendants
Similar to but for categories. 

a

b

c

m

p

s

t

w

This lets you print out an index of all published posts on your site. By default, posts are listed in alphabetical order grouped by their first letters. There are CSS classes for each section, letter and list allowing you to customise the appearance.order: text, either ASC or DESCorderby: text, popular options include “title”, “date”, “ID”, and “rand”. See WP_Query for a list.separate: true/false (defaults to true), does not separate the lists by first letter when set to false.

For developers

How do I customise my anchors?

If you’re still not happy with the anchors, you can modify them to suit your needs through a custom function hooked into the toc_url_anchor_target filter. As an example, place the below code snippet into your functions.php file to convert all anchors to uppercase.

function my_custom_anchor( $anchor )
{
	return strtoupper( $anchor );
}
add_filter( 'toc_url_anchor_target', 'my_custom_anchor' );

toc_get_index( $content = ”, $prefix_url = ” )

返回目录的HTML格式字符串,而没有周围的UL或OL标签,以允许主题编辑器向外部列表提供其自己的ID和/或类。

这两个参数都是可选的:

  • $content是带有标题的全部内容。如果为空,则默认为$ post中的当前内容(例如,在“循环”中)。
  • $prefix_url是以锚作为前缀的URL。如果提供了字符串,则将按原样使用。如果设置为“ true”,则将尝试从$ post对象获取永久链接。

这些示例假定您处于“循环”中:

获取当前页面的索引

echo '<ul id="my_toc">' . toc_get_index() . '</ul>';

创建所有子项目及其标题的清单

$children = new WP_Query(array(
	'post_parent' => get_the_ID(),
	'posts_per_page' => -1	// get all children
));
while ( $children->have_posts() ) {
	$children->the_post();
	echo 
		'<h3>' . get_the_title() . '</h3>' .
		'<ul>' . toc_get_index( get_the_content(), get_permalink( $children->post->ID ) ) . '</ul>'
	;
}
wp_reset_postdata();

版本控制方案

我采用了相同的Ubuntu版本控制方案,因此第一个版本是1107。

同月的其他发行版将是点发行,例如,2011年7月的第二个发行版是1107.1。

我喜欢它,该如何表达我的赞赏?

如果您对这个插件印象深刻,并且想以某种方式表示感谢,而不是像我一样发送捐款,请捐款给您选择的慈善机构。如有需要,请随时在此处留言。

我绝不会要求任何形式的奖励或补偿。帮助他人实现目标就足够了🙂

2020-07-20
WP文档

add_options_page()将子菜单页面添加到“设置”主菜单 - wordpess函数

2020-4-30 14:27:18

WP文档

关于LightSNS主题的一些介绍

2020-7-31 17:30:19

⚠️
Npcink上的部份代码及教程来源于互联网,仅供网友学习交流,若您喜欢本文可附上原文链接随意转载。
无意侵害您的权益,请发送邮件至 link@baimu.org 或点击右侧 私信:Muze 反馈,我们将尽快处理。
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
搜索