keesiemeijer / additional-content
在单个文章页面上显示在文章内容之前或之后的内容。
This package is auto-updated.
Last update: 2024-09-12 05:59:02 UTC
README
版本: 1.3.0
至少需要: 4.0
已测试到: 4.8
在单个文章页面上显示在文章内容之前或之后的内容。在编辑或发布文章屏幕上,按文章添加内容(例如短代码)。
安装
通过Composer安装到您的WordPress插件目录
composer create-project keesiemeijer/additional-content
或在插件目录中克隆GitHub存储库
git clone https://github.com/keesiemeijer/additional-content.git
或直接下载ZIP文件[下载链接]
PHP要求
此插件需要WordPress推荐的PHP版本,至少为5.4.0或更高。
WordPress的最小PHP版本为5.2.4。这是一个自2011年初以来未受支持的版本。PHP 5.3.*版本自2014年8月起也停止了支持。这意味着这些版本不会收到任何更新,这使它们可能存在安全隐患。[更新PHP](http://www.wpupdatephp.com)
注意:在旧版本的PHP上激活插件时,插件会显示通知。[查看通知](https://github.com/keesiemeijer/additional-content/blob/HEAD//../screenshots/assets/img/admin-notice.png?raw=true)
优先选项是什么?
此插件基本上是the_content过滤器的用户界面。此过滤器允许主题和插件在内容显示之前更改(或向内容添加内容)。过滤器的默认优先级为10。更高的数字对应于添加额外内容的较晚执行。此选项允许您在添加内容之前或之后显示其他插件。
在额外内容中使用HTML
可以在额外内容中使用与文章(文本)编辑器中允许的相同的HTML标签。如果您想在内容中使用<script>
标签,则用户必须具有未过滤HTML权限(超级管理员、管理员和编辑角色)。
更改元框文本字符串
假设您想使用此插件让作者在单个文章页面的内容后添加短代码。所有元框文本字符串都可以通过additional_content_metabox_text
过滤器进行更改。将其放在您的(子)主题的functions.php文件中或用于插件中。
add_filter( 'additional_content_metabox_text', 'change_additional_content_text_strings' ); function change_additional_content_text_strings( $text ) { $text['title'] = __( 'Add Shortcodes', 'additional-content' ); $text['content'] = __( 'Shortcode', 'additional-content' ); $text['prepend_content'] = __( 'Prepend Shortcode', 'additional-content' ); $text['append_content'] = __( 'Append Shortcode', 'additional-content' ); $text['prepend_append_content'] = __( 'Prepend and Append Shortcode', 'additional-content' ); $text['prepend'] = __( 'Prepend shortcode', 'additional-content' ); $text['append'] = __( 'Append shortcode', 'additional-content' ); $text['priority'] = __( 'Priority', 'additional-content' ); $text['add_row'] = __( 'Add shortcode', 'additional-content' ); $text['add_more_row'] = __( 'Add more shortcodes', 'additional-content' ); $text['remove_row'] = __( 'Remove', 'additional-content' ); $text['header_info'] = __( 'Add shortcodes to the post content on single post pages. ', 'additional-content' ); $text['priority_info'] = ''; return $text; }
选项显示
可以使用additional_content_metabox_options
过滤器删除 prepend、append和priority字段。将其放在您的(子)主题的functions.php文件中或用于插件中。
add_filter( 'additional_content_metabox_options', 'remove_additional_content_options' ); function remove_additional_content_options( $options ) { $options['append_prepend'] = false; $options['priority'] = false; return $options; }
在除了单篇文章页面之外的其他页面上的额外内容
如果您想在除了单篇文章页面之外的其他页面上显示额外内容,请使用additional_content_add_content
过滤器。将其放在您的(子)主题的functions.php文件中或用于插件中。此示例将额外内容添加到主页上的文章。
add_filter( 'the_content', 'additional_content_home_page' ); function additional_content_home_page( $content ) { // Check if we're on the home page if ( !is_home() ) { return $content; } // Check if this is the main query and inside the loop. if ( in_the_loop() && is_main_query() ) { // Check if the plugin function get_content() exists. if ( function_exists( 'keesiemeijer\Additional_Content\\get_content' ) ) { // Add the additional content to the post content with the get_content() function. // Content and post id are required. // Post id is available inside the loop. $content = keesiemeijer\Additional_Content\get_content( $content, get_the_ID() ); } } return $content; }