[wordpress插件] Ambrosite Body Class EnhancedAmbrosite增强身体等级

wordpress 插件 文章 2020-02-17 14:10 526 0 全屏看文

AI助手支持GPT4.0

评分
100
描述

When activated, this plugin causes the body_class template tag to output five additional classes.

激活后,此插件将使body_class模板标签输出另外五个类。

On single posts (is_single) :
    

在单个帖子上(is_single):
    

postname-[permalink slug]
    

帖子名称-[永久链接子弹]
    

single-[category slug]
    

单类别的子弹
    

parent-[parent category slug] (all parent and grandparent categories in a hierarchy of any depth)

parent- [parent category slug](任意深度的层次结构中的所有父级和祖父母级)

On pages (is_page) :
    

在页面上(is_page):
    

pagename-[permalink slug]

页面名称-[永久链接段]

On category archives (is_archive and is_category) :
    

关于类别档案(is_archive和is_category):
    

parent-category-[parent category slug] (all parent and grandparent categories in a hierarchy of any depth)

parent-category- [parent category slug](任何深度层次结构中的所有父级和祖父母级)

Custom Taxonomies

自定义分类法

As of version 1.3, the plugin now supports custom hierarchical taxonomies.

从1.3版开始,该插件现在支持自定义层次分类法。

The new body classes take the following form:

新的正文类采用以下形式:

On single posts (is_single) :
    

在单个帖子上(is_single):
    

single-[taxonomy]-[term slug]
    

单项[分类法]-[词条]
    

parent-[taxonomy]-[parent term slug] (all parent and grandparent terms in a hierarchy of any depth)

parent- [分类法]-[parent term slug](任何深度层次结构中的所有父项和祖父母项)

On taxonomy archives (is_archive and is_tax) :
    

关于分类档案(is_archive和is_tax):
    

parent-term-[parent term slug] (all parent and grandparent terms in a hierarchy of any depth)

parent-term- [parent term slug](任何深度层次结构中的所有父项和祖父母项)

For single posts, the taxonomy name is included in the class name, because I felt it was important to be able to distinguish between taxonomies in cases where a post is assigned to more than one custom taxonomy, and when the same term might

对于单个帖子,分类名称包含在类名称中,因为在将一个帖子分配给多个自定义分类的情况下,以及当相同术语可能

appear in two or more taxonomies.

出现在两个或多个分类中。

For example, suppose you had a real estate site with property listings in New York City, and you had two custom taxonomies defined: City and State.

例如,假设您在纽约市有一个房地产网站,上面有房地产清单,并且定义了两个自定义分类法:城市和州。

Then the classes would look like this:

然后这些类将如下所示:

single-city-new-york single-state-new-york

 纽约州单市纽约州

Multisite Support

多站点支持

As of version 1.3, the plugin now supports multisite installations.

从1.3版开始,该插件现在支持多站点安装。

If a multisite install is detected, the plugin will output the follow additional body class on every page of the site:

如果检测到多站点安装,则插件将在站点的每个页面上输出以下附加正文类:

site-[site ID]

  site- [站点ID]

Examples

示例

If you have a post titled “Top 10 Decorating Ideas”, in category “Christmas”, with a parent category of “Holidays” and a grandparent category of “Calendar”, the additional body classes will be as follows:

如果您在“圣诞节”类别中有一个标题为“十大装饰创意”的帖子,其父类别为“假日”,祖父母类别为“日历”,则其他身体类别如下:

p>

>

postname-top-10-decorating-ideas single-christmas parent-holidays parent-calendar

  postname-top-10-decorating-ideas Single-christmasparent-holidaysparent-calendar

Why is this useful?

这为什么有用?

Because it enables you to style individual posts and pages, as well as entire categories of posts, using only CSS, without having to edit the template files or create new templates.

因为它使您可以仅使用CSS设置单个帖子和页面以及整个帖子类别的样式,而无需编辑模板文件或创建新模板。

Continuing the above example, if I wanted to give all of the posts in the Christmas category a green heading (to give them some extra holiday cheer), I could use a CSS selector like this:

继续上面的示例,如果我想给圣诞节类别中的所有帖子都添加一个绿色标题(为他们提供一些额外的节日气氛),我可以使用这样的CSS选择器:

body.single-christmas h1 {    

  body.single-christmas h1 {    

color: green;

颜色:绿色;

}

}

Going further, suppose I want to attach a background image of a Christmas tree ONLY to the “Top 10 Decorating Ideas” post:

再进一步,假设我只想将圣诞树的背景图像附加到“十大装饰创意”帖子中:

body.postname-top-10-decorating-ideas div.post {    

  body.postname-top-10-decorating-ideas div.post {    

background: url('images/xmas_tree.gif') no-repeat left top;

背景:url('images / xmas_tree.gif')不重复左上;

}

}

What if I want all posts categorized under Holidays (Christmas, Thanksgiving, Easter, whatever) to have a sidebar with a gold border?

如果我希望所有分类为“假期”(圣诞节,感恩节,复活节等)的帖子都带有带有金色边框的侧边栏,怎么办?

body.parent-holidays div#sidebar,  /* all posts assigned to a subcategory of Holidays */

  body.parent-holidays div#sidebar,/ *所有分配给假期子类别的帖子* /

body.single-holidays div#sidebar { /* any posts assigned directly to the Holidays category */    

body.single-holidays div#sidebar {/ *任何直接分配给“假期”类别的帖子* /    

border: solid 2px gold;

边框:纯2px金色;

}

}

These are just a few examples.

这些只是几个例子。

If you are experienced in writing CSS selectors, you will find many more uses for the new body classes.

如果您有编写CSS选择器的经验,将会发现新的body类有更多用途。

For further discussion, check this support forum thread: https://wordpress.org/support/topic/393942

有关进一步的讨论,请查看以下支持论坛主题:https://wordpress.org/support/topic/393942

安装步骤

    • Upload ‘ambrosite-body-class.php’ to the ‘/wp-content/plugins/’ directory.
    • 将“ ambrosite-body-class.php”上传到“ / wp-content / plugins /”目录。

    • Activate the plugin through the ‘Plugins’ menu in WordPress.
    • 通过WordPress中的“插件”菜单激活插件。

    • Verify your theme has the body_class function on the body element in header.php, as explained in the WordPress Codex: https://codex.wordpress.org/Template_Tags/body_class
    • 确认主题在header.php中的body元素上具有body_class函数,如WordPress Codex中所述:https://codex.wordpress.org/Template_Tags/body_class

下载地址
https://downloads.wordpress.org/plugin/ambrosite-body-class-enhanced.zip
-EOF-

AI助手支持GPT4.0