So i have this php file called single-portfolio.php. In that file I have some code that makes certain things appear if there's content entered into the admin side of a portfolio item. In this case, whenever someone has entered data into the case-study field in the admin side, the div shows up on the page:
<?php if( (types_render_field( "case-study")) != "" ) { ?> <div class="right-details"> <div class="badge badge-3" title="Case Study"></div> <div class="right-content"><?php echo(types_render_field("case-study", array("alt"=>"Case Study", "width"=>"300","height"=>"200","proportional"=>"true"))); ?></div> </div> <?php } ?>
That works perfectly fine on single-portfolio.php page. However, im also working on a file called shortcodes.php which deals with all of the theme's shortcodes, including the portfolio loop. I've found where to add my badges into the php and they all show up fine using this code:
$output .= '<div class="badgecontainer"><div class="port-badge pbadge1"></div><div class="port-badge pbadge2"></div><div class="port-badge pbadge3"></div></div><img src="' . $post_thumbnail_img[0] . '" alt="' . $post_thumbnail_data['alt'] . '" title="' . $post_thumbnail_data['title'] . '" class="entry-image ' . $post_thumbnail_data['class'] . '">';
So with my novice php skills i tried slapping some if statements into that code to see if i could get pbadge1 to only show if the case-study field was filled, but the code i put in completely breaks the page. What i tried is highlighted.
$output .= '<div class="badgecontainer">' . if( (types_render_field( "case-study")) != "" ) { . '<div class="port-badge pbadge1"></div>' . } . '<div class="port-badge pbadge2"></div><div class="port-badge pbadge3"></div></div><img src="' . $post_thumbnail_img[0] . '" alt="' . $post_thumbnail_data['alt'] . '" title="' . $post_thumbnail_data['title'] . '" class="entry-image ' . $post_thumbnail_data['class'] . '">';
If anyone could give me any insight as to why this is happening or what i could do to fix it i would be so happy i would faint! Thanks!