[wordpress插件] Content Sectioner内容分区

wordpress 插件 文章 2020-04-01 08:00 496 0 全屏看文

AI助手支持GPT4.0

评分
0
描述

Most modern websites have pages that break the content into multiple sections, with changing background colors and graphics marking the breaks between sections.

大多数现代网站上都有将内容分成多个部分的页面,不断变化的背景颜色和图形标记了部分之间的间隔。

In order for a page to be broken into sections, typically there needs to be additional markup within the HTML (ie. div tags) that can be targeted in the stylesheet for formatting.

为了将页面分为多个部分,通常需要在HTML中添加其他标记(即 div 标签),这些标记可以在样式表中进行格式化。

However, most content authors don't want to think about techie stuff like div tags, and prefer to work in the Visual editor which only provides for semantic markup (“Paragraph”, “Heading 1”, etc

但是,大多数内容作者都不想考虑诸如 div 标签之类的技术性东西,而是喜欢在仅提供语义标记(“段落”,“标题1”等)的Visual编辑器中工作。

.).

)。

Content Sectioner takes advantage of WordPress’s content filtering mechanism and makes it easy for a theme developer to insert the necessary sectioning markup auto-magically while allowing content authors to still work as they prefer.

Content Sectioner利用WordPress的内容过滤机制,使主题开发人员可以轻松地自动神奇地插入必要的分区标记,同时允许内容作者按自己的意愿工作。

It looks for specified landmarks within the content (such as h3 tags) and performs the necessary code insertions or replacements.

它在内容中查找指定的界标(例如 h3 标记),并执行必要的代码插入或替换。

It does this using a concise and easy-to-use notation, relieving the theme developer from having to write (often repetitive) regular expressions and string manipulation.

它使用简洁且易于使用的符号来执行此操作,从而使主题开发人员不必编写(通常是重复的)正则表达式和字符串操作。

A concrete example

一个具体例子

Suppose you’re working on a site and you want the About page (with slug about) to have an inset in the middle of it with a blue background setting it apart.

假设您正在某个网站上工作,并且希望“关于”页面(带有错误的 about )在其中间具有一个插入物,并且背景为蓝色。

The inset should contain the first occurence of a “Heading 3” and all the paragraphs up until just before the next “Heading 2”.

插图应包含第一次出现的“标题3”和所有段落,直到下一个“标题2”之前。

The stylesheet will apply the changing background to elements with the selector .inset.

样式表将使用选择器 .inset 将变化的背景应用于元素。

Assuming your index.php file contains something like this:

假设您的 index.php 文件包含以下内容:

  <?php  

$current_slug = get_queried_object()->post_name;  

$ current_slug = get_queried_object()-> post_name;  

get_template_part('content', $current_slug);

get_template_part('content',$ current_slug);

?>

?>

Then in the file content-about.php, you can set up the Content Sectioner like so:

然后在文件 content-about.php 中,您可以像这样设置Content Sectioner:

  <?php  

$sectioner = new ContentSectioner();  

$ sectioner = new ContentSectioner();  

$sectioner->replace_first(    

$ sectioner-> replace_first(    

array(      

数组(      

'open_tag' => 'h3',      

'open_tag'=>'h3',      

'open_insert' => '

',      

'open_insert'=>'

',      

'open_policy' => 'before',      

'open_policy'=>'之前',      

'close_tag' => 'h2',      

'close_tag'=>'h2',      

'close_insert' => '

',      

'close_insert'=>'',      

'close_policy' => 'before'    

'close_policy'=>'之前'    

)  

)  

);  

);  

// Do the usual Loop thing here...

//在这里做通常的Loop事情...

?>

?>

The About page (and only the About page) will have this inset section inserted.

“关于”页面(并且只有“关于”页面)将插入此插图部分。

You can provide replacement rules that replace/insert at the first occurrence of a match, the next occurrence, all remaining occurrences, or all occurrences in the entire piece of content.

您可以提供替换规则,这些规则在匹配的第一个匹配项,下一个匹配项,所有剩余匹配项或整个内容中的所有匹配项处进行替换/插入。

You can place the inserted HTML before or after a match, or replace the match.

您可以将插入的HTML放在匹配之前或之后,或替换匹配。

Also, you can match a closing tag by simply providing the preceding slash character (eg. ‘/h2’).

另外,您只需提供前面的斜杠字符(例如“ / h2”)即可匹配结束标记。

Tag matches will match against any variant of a tag (upper or lowercase, with or without attributes, as an opening tag or as a self-closing tag like


).

标签匹配项将与标签的任何变体(大写或小写,带有或不带有属性,作为开始标签或作为自闭合标签,如


)匹配。

In the rare case that something other than a tag needs to be matched, you can supply a raw regex instead of a tag.

在极少数情况下,除了标签以外还需要匹配其他内容时,您可以提供原始的正则表达式来代替标签。

Providing instructions

提供说明

As the theme developer, you likely would want to let the content authors know that this magic insertion of sections will occur, and what landmarks need to be present in their content to trigger the sectioning.

作为主题开发人员,您可能希望让内容作者知道将出现这种神奇的部分插入,以及在其内容中需要出现哪些界标以触发该部分。

In some file in your theme that gets loaded for every page (most likely functions.php), you can provide such instructions along with the slug for the page to which the instructions apply.

在您的主题的某个文件中,该文件会为每个页面加载(很可能是 functions.php ),您可以提供此类说明以及适用于该说明的页面的信息。

The instructions will appear at the top of the Edit Page page in the admin.

说明将显示在管理员“编辑页面”页面的顶部。

ContentSectioner::provide_instructions('about', "  

  ContentSectioner :: provide_instructions('about',“  

A blue background will be placed behind everything starting at the first Heading 3  

从第一个标题3开始,蓝色背景将被放置在所有内容的后面  

through just before the next Heading 2.");

直到下一个标题2。”);

Full User Guide

完整用户指南

For full documentation and more sample use cases, visit the Content Sectioner homepage.<

有关完整文档和更多示例用例,请访问 Content Sectioner主页。<

/p>

/ p>

安装步骤

The plugin may be used either as a conventional plugin, or since it is only one class file, embedded within a custom theme.

该插件既可以用作常规插件,又可以嵌入自定义主题中,因为它只是一个类文件。

As a plugin from the WordPress dashboard

作为WordPress仪表板中的插件

    1. Visit ‘Plugins > Add New’
    2. 访问“插件>添加新内容”

    3. Search for ‘Content Sectioner’
    4. 搜索“内容分节器”

    5. Activate Content Sectioner from your Plugins page
    6. 从“插件”页面激活“内容分区器”

    As a plugin from WordPress.org

    作为WordPress.org的插件

      1. Download Content Sectioner
      2. 下载内容分节器

      3. Upload the ContentSectioner.php file to the /wp-content/plugins directory
      4. ContentSectioner.php 文件上传到 / wp-content / plugins 目录

      5. Activate Content Sectioner from your Plugins page
      6. 从“插件”页面激活“内容分区器”

      Embedded in a custom theme

      嵌入自定义主题

        1. Download Content Sectioner
        2. 下载内容分节器

        3. Either concatenate the contents of the ContentSectioner.php file into your functions.php file, or place it in your theme folder and require

        4. ContentSectioner.php 文件的内容连接到您的 functions.php 文件中,或将其放置在主题文件夹中,然后 require

          it when needed

        5. 需要的时候

下载地址
https://downloads.wordpress.org/plugin/content-sectioner.zip
-EOF-

AI助手支持GPT4.0