5

如何创建WordPress简码获取指定分类目录图像描述显示?

 2 years ago
source link: https://www.chenweiliang.com/cwl-20133.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

广告

当前位置: 陈沩亮博客 » WordPress » 如何创建WordPress简码获取指定分类目录图像描述显示?

2022年1月27日

如何创建一个简码来显示类别描述?

比如,想在下图这里的WordPress分类描述,在指定文章页面显示该分类描述:

如何创建WordPress简码在指定文章页面显示分类描述?

如何创建WordPress简码获取指定分类目录图像描述显示?

假设你希望能够显示某些帖子和产品 (WooCommerce) 类别的描述通过简码的页面或帖子,但是不知道如何使用代码创建一个简单的WordPress短代码。

请将以下代码添加到 functions.php 文件中:

add_shortcode('cat_description', 'my_cat_description_shortcode');
function my_cat_description_shortcode($atts){

$a = shortcode_atts( array(
'id' => 0,
), $atts );

return category_description($a['id']);

}

如果你 想要从模板调用WordPress简码(除非你向简码添加更多内容,否则不必要)你可以使用此代码:

<?php echo do_shortcode('[cat_description id="' . $category_id . '"]'); ?>
  • 其中category_id 是分类的ID。

如何通过WP简码在指定文章页面获取WordPress当前分类描述显示?

在指定文章页面显示分类描述,添加以下WordPress简码:

[cat_description id=""]
  • 如果分类目录描述简码id中间的引号留空,就可以直接调用当前WordPress分类目录描述图像。

希望陈沩亮博客( https://www.chenweiliang.com/ ) 分享的《如何创建WordPress简码获取指定分类目录图像描述显示?》,对您有帮助。

欢迎分享本文链接:https://www.chenweiliang.com/cwl-20133.html

欢迎加入陈沩亮博客的 Telegram 频道,获取最新更新!

喜欢就分享和按赞!
您的分享和按赞,是我们持续的动力!

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK