开发者

WordPress Conditional Content by Multiple Post Types

开发者 https://www.devze.com 2023-03-27 21:57 出处:网络
working on a highly complex WordPr开发者_运维知识库ess theme that features many different custom post types.I was under the impression that the following code would check to see if the current post wa

working on a highly complex WordPr开发者_运维知识库ess theme that features many different custom post types. I was under the impression that the following code would check to see if the current post was of the type "philosopher" and then run the PHP conditional that follows it only if the post is in that type:

<?php if (get_post_type() == 'philosopher') { ?>

Unfortunately, my expectation was that to make the same item conditional for "philosopher", "text", and "original" my code should look like this:

<?php if (get_post_type() == 'philosopher','text','original') { ?>

But alas, I was wrong. I did get the following code to work, but I'm wondering if there's a cleaner way to do this (or if I'm somehow missing something)

        <?php if ( (get_post_type() == 'philosimply') || (get_post_type() == 'text') || (get_post_type() == 'original'))  { ?>


if ( in_array(get_post_type(), array('philosopher','text','original')) ){ ... }

http://www.php.net/manual/en/function.in-array.php

Is that, what you are looking for?

HTH

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号