[wordpress插件] Author Categories作者类别

wordpress 插件 文章 2020-02-23 14:10 485 0 全屏看文

AI助手支持GPT4.0

评分
0
描述

Numerous people are using WordPress for blogging and in many cases there are more than one authors on a website.

许多人正在使用WordPress进行博客撰写,并且在许多情况下,网站上的作者不止一个。

It’s uncomfortably surprising that WordPress doesn’t support out of the box a category menu for each author separately.

令人惊讶的是,WordPress不开箱即用地不为每个作者单独提供类别菜单。

I was looking for this feature online for my personal need but couldn’t find it on any plugin.

我一直在网上寻找此功能以满足我的个人需求,但在任何插件上都找不到。

To be exact I was using a modified version of another similar plugin but that was until version 2.3 where the database structure changed for WordPress and it simply stopped working.

“>另一个类似的插件,但是直到2.3版本,WordPress的数据库结构发生了变化,并且只是停止了工作。

As I saw it, it wasn’t worth fixing old, deprecated (and highly cluttered) code, and there weren’t any other solutions out there, so I decided to create a new plugin.

如我所见,修复旧的,已过时(且混乱)的代码是不值得的,并且那里没有其他解决方案,所以我决定创建一个新的插件。

Thankfully the new database and API made it as easy as I had hoped for.

幸运的是,新的数据库和API使它像我所希望的那样简单。

I ended up with this plugin, that was created as a wrapper of the default category menu.

我最终得到了这个插件,它是作为默认类别菜单的包装而创建的。

It is lightweight and can easily plug-in, plug-out.

它很轻巧,可以轻松插入,拔出。

Furthermore, being an extension of the default category menu, means that none of the functionality (sorting, post count etc.) is lost.

此外,作为默认类别菜单的扩展,意味着没有任何功能(排序,发布计数等)丢失。

In fact it can be easily extended and could support future versions of the blogging platform for years to come.

实际上,它可以轻松扩展,并可以在未来几年内支持博客平台的未来版本。

Usage

用法

After you upload an activate the plugin through your admin panel, all you need to do is call the custom function wp_author_categories() that will create an author’s menu for you.

通过管理面板上传激活插件后,您所需要做的就是调用自定义函数wp_author_categories(),该函数将为您创建作者菜单。

Notice that this only works in author pages and will revert to the default category menu in any other case.

请注意,这仅在作者页面中有效,在任何其他情况下,都将还原为默认的类别菜单。

If you are using the default template, you can easily find this line in “sidebar.php” (that displays the category menu):
            

如果使用默认模板,则可以在“ sidebar.php”(显示类别菜单)中轻松找到此行:
            

< ?php wp_list_categories('show_count=1&title_li=Categories’);

<?php wp_list_categories('show_count = 1&title_li = Categories');

?>

?>

You can replace it with this condition that will use the wp_author_categories() function instead, when you are visiting the author pages

您可以用这种条件替换它,当您访问作者页面时,将使用wp_author_categories()函数

        

  <?php        

/*        

/ *        

* First write down the arguments you want to use for you menu and store them in a variable.        

*首先写下您要用于菜单的参数,然后将其存储在变量中。        

* These are the same for the default menu ("wp_list_categories") and the author menu ("wp_author_categories")        

*这些与默认菜单(“ wp_list_categories”)和作者菜单(“ wp_author_categories”)相同        

* you can find more information on the options you can use here: https://codex.wordpress.org/Template_Tags/wp_list_categories        

*您可以在此处找到有关选项的更多信息:https://codex.wordpress.org/Template_Tags/wp_list_categories        

*/        

* /        

$args = 'show_count=1&title_li=

Categories

';        

$ args ='show_count = 1&title_li =

类别';        

if($author){            

如果($作者){            

wp_author_categories($args);        

wp_author_categories($ args);        

} else{            

}其他{            

wp_list_categories($args);        

wp_list_categories($ args);        

}        

}        

?>

?>

Alternatively, and if you already have an “author.php” file in your template folder, you can simply rename “wp_list_categories()” to “wp_author_categories()”, passing the same arguments.

或者,如果您的模板文件夹中已经有一个“ author.php”文件,则可以简单地将“ wp_list_categories()”重命名为“ wp_author_categories()”,并传递相同的参数。

To uninstall, it’s as easy as doing the reverse actions.

要卸载,就像执行反向操作一样容易。

Delete all references of the wp_author_categories() function from your template files and uninstall the plugin through that WordPress’s admin panel.

从您的模板文件中删除wp_author_categories()函数的所有引用,然后通过该WordPress的管理面板卸载该插件。

License

许可证

This work is released under the terms of the GNU General Public License:

此作品是根据GNU通用公共许可证的条款发布的:

http://www.gnu.org/licenses/gpl-2.0.txt

http://www.gnu.org/licenses/gpl-2.0.txt

安装步骤

    1. Upload the file “wp_author_categories.php” in your “wp-content/plugins” directory
    2. 在“ wp-content / plugins”目录中上传文件“ wp_author_categories.php”

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

    5. Inlude the function “wp_author_categories()” in your template files
    6. 在模板文件中包含函数“ wp_author_categories()”

    More detailed information is provided in the “Usage” section of this document.

    更多详细信息,请参见本文档的“用法”部分。

下载地址
https://downloads.wordpress.org/plugin/author-categories.1.0.zip
-EOF-

AI助手支持GPT4.0