我遇到了这个if语句的问题,它位于wordpress循环中。第一个if语句 - if ( $caption == "1")
- 似乎有效,但第二个似乎总是通过,即使$image_title
没有==那些字符串。
foreach ( $images as $attachment_id => $attachment ) {
// $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
$image_title = $attachment->post_title;
$caption = $attachment->post_excerpt;
$description = $attachment->post_content;
$img_url = get_post_meta( $attachment->ID, '_gallery_link_url', true ); //WP Gallery Custom Links extra URL field
if ( $caption == "1") {
echo '<div class="imagewrapb">';
if ($image_title == "Branding" or "Print" or "Digital" or"Packaging") {
echo '<h3>'.$image_title.'</h3>';
echo wp_get_attachment_image( $attachment_id, '' );
echo '<a href="'.$img_url.'">'.'<div class="hover">'.$description.'</div>'.'</a>';
var_dump($image_title);
}
else if ($image_title == "Twitter") {
echo '<h3>'.$image_title.'</h3>';
echo wp_get_attachment_image( $attachment_id, '' );
echo '<div class="twitterfeed"><h2>@V_IX</h2><ul id="twitter_update_list"><li>Twitter feed loading</li></ul></div>';
}
else if ($image_title == "Facebook") {
echo '<h3>'.$image_title.'</h3>';
echo wp_get_attachment_image( $attachment_id, '' );
echo '<div class="facebookfeed">';
include 'facebook.php';
echo '</div>';
}
else {
if ( !empty($img_url) /*img_url exists*/ ){
echo '<h3>'.$image_title.'</h3>';
if ( !empty($description) /*description exists*/ ){
echo wp_get_attachment_image( $attachment_id, '' );
echo '<a href="'.$img_url.'">'.'<div class="hover">'.$description.'</div>'.'</a>';
}
else {
echo '<a href="'.$img_url.'">';
echo wp_get_attachment_image( $attachment_id, '' );
echo '</a>';
}
}
else { /*img_url doesnt exist*/
echo '<h3>'.$image_title.'</h3>';
if ( !empty($description) /*description exists*/ ){
echo wp_get_attachment_image( $attachment_id, '' );
echo '<div class="hover">'.$description.'</div>';
}
else {
echo wp_get_attachment_image( $attachment_id, '' );
}
}
}
echo '</div>';
}
else {
echo '<div class="imagewrap">';
if ($image_title == "Branding" || "Print" || "Digital" || "Packaging") {
echo '<h3>'.$image_title.'</h3>';
echo wp_get_attachment_image( $attachment_id, '' );
echo '<a href="'.$img_url.'">'.'<div class="hover">'.$description.'</div>'.'</a>';
}
else if ($image_title == "Twitter" ) {
echo '<h3>'.$image_title.'</h3>';
echo wp_get_attachment_image( $attachment_id, '' );
echo '<div class="twitterfeed"><h2>@V_IX</h2><ul id="twitter_update_list"><li>Twitter feed loading</li></ul></div>';
}
else if ($image_title == "Facebook") {
echo '<h3>'.$image_title.'</h3>';
echo wp_get_attachment_image( $attachment_id, '' );
echo '<div class="facebookfeed">';
include 'facebook.php';
echo '</div>';
}
else {
if ( !empty($img_url) /*img_url exists*/ ){
echo '<h3>'.$image_title.'</h3>';
if ( !empty($description) /*description exists*/ ){
echo wp_get_attachment_image( $attachment_id, '' );
echo '<a href="'.$img_url.'">'.'<div class="hover">'.$description.'</div>'.'</a>';
}
else {
echo '<a href="'.$img_url.'">';
echo wp_get_attachment_image( $attachment_id, '' );
echo '</a>';
}
}
else { /*img_url doesnt exist*/
echo '<h3>'.$image_title.'</h3>';
if ( !empty($description) /*description exists*/ ){
echo wp_get_attachment_image( $attachment_id, '' );
echo '<div class="hover">'.$description.'</div>';
}
else {
echo wp_get_attachment_image( $attachment_id, '' );
}
}
}
echo '</div>';
}
}
将if语句更改为(我认为是什么?)更正 - if (($image_title == "Branding")||($image_title == "Print")||($image_title == "Digital")||($image_title =="Packaging")) {
- 似乎没有显示带有'branding'等字符串的变量。
答案 0 :(得分:5)
if ($image_title == "Branding" or "Print" or "Digital" or "Packaging")
必须是:
if ($image_title == 'Branding' || $image_title == 'Print' || $image_title == 'Digital' || $image_title == 'Packaging')