WordPress Conditional Content by Multiple Post Types
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
精彩评论