admin管理员组文章数量:1122846
I need to do the following: The sense if I have a class dportfolio
- show
a category dportfolio
. Otherwise show usual category.
I use:
if ( class_exists( 'DPortfolio' ) ) {
echo DPortfolio::instance()->dportfolio_get_category();
}; ?>
and when I try to add a second part of a code:
the_category(', ')
with if/else
statement, I receive a php error.
Any suggestions to write this function in a correct way?
I need to do the following: The sense if I have a class dportfolio
- show
a category dportfolio
. Otherwise show usual category.
I use:
if ( class_exists( 'DPortfolio' ) ) {
echo DPortfolio::instance()->dportfolio_get_category();
}; ?>
and when I try to add a second part of a code:
the_category(', ')
with if/else
statement, I receive a php error.
Any suggestions to write this function in a correct way?
Share Improve this question edited Oct 21, 2014 at 6:44 Pieter Goosen 55.4k23 gold badges115 silver badges209 bronze badges asked Oct 21, 2014 at 6:41 MichaelNagvalMichaelNagval 12 Answers
Reset to default 0Is the code used inside of the loop? The following code should work:
if ( class_exists( 'DPortfolio' ) ) {
echo DPortfolio::instance()->dportfolio_get_category();
}else{
the_category();
//or echo get_the_category();
}
If outside of the loop you can try echo get_the_category( $post_id )
to show the categories.
Note: As you are getting an error, if you edit the question, include the full code snippet with if/else
and include the error, then it's easier to help.
You can achieve this by using an if/else
statement along with the has_category()
function in wp
if ( class_exists( 'DPortfolio' ) && has_category( 'dportfolio' ) ) {
echo DPortfolio::instance()->dportfolio_get_category();
} else {
the_category(', ');
}
本文标签: categoriesthecategory ifelse statement
版权声明:本文标题:categories - the_category ifelse statement 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736294908a1929457.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论