我希望在我的帖子模板中嵌入几个短代码,但我希望标签有特定类别(和子类别)的条件。
我已经看过了抄本,但我不知道从哪里开始。
我希望在我的帖子模板中嵌入几个短代码,但我希望标签有特定类别(和子类别)的条件。
我已经看过了抄本,但我不知道从哪里开始。
如果要将代码直接嵌入到模板文件中,为什么还要使用短代码呢?
只需从add_shortcode()
函数调用,并将其添加到模板中,包装在适当的条件标记中,如in_category()
, e、 g.:
if ( in_category( $cat ) ) {
// put shortcode code here
}
注:该$cat
参数可以是ID、名称或slug。如果您熟悉此代码<?php $pattern = get_shortcode_regex(); preg_match(\'/\'.$pattern.\'/s\', $posts[0]->post_content, $matches); if (is_array($matches) && $matches[2] == \'YOURSHORTCODE\') { //shortcode is being used }&#