kevinh81 Posted September 15, 2010 Share Posted September 15, 2010 I'm not fluent in php, but I think this should be an easy fix for someone who is. Basically, I have a Wordpress theme that auto generates the images from posts in each slide of the feature slider on the homepage. Goal: for php to remove the css border around the image if it is a .png file Purpose: I want borders on photos in the feature slider, but no borders on images with transparent backgrounds... like free floating logos. So I figured I could use an if/else statement to determine if the file has a .png extension... if it does then it inserts the html style to remove the border. Here is the original code from the theme where it gets the image <a href="<?php echo($arr[$i]["permalink"]); ?>" title="<?php printf(__('Permanent Link to %s', 'TheCorporation'), $arr[$i]["fulltitle"]) ?>"> <?php print_thumbnail($arr[$i]["thumb"], $arr[$i]["use_timthumb"], $arr[$i]["fulltitle"] , $width, $height, 'thumb'); ?> </a> Here is what I was trying to get to work.. I tried taking the variable for $file from the code I assumed was populating the image path <?php $file = `print_thumbnail($arr[$i]["thumb"]`; $ext = `pathinfo($file, PATHINFO_EXTENSION)`; ?> <a <?php if($ext == ".png") echo ?>style="border:none 0px !important;" <?php ; else null; ?> href="<?php echo($arr[$i]["permalink"]); ?>" title="<?php printf(__('Permanent Link to %s', 'TheCorporation'), $arr[$i]["fulltitle"]) ?>"> <?php print_thumbnail($arr[$i]["thumb"], $arr[$i]["use_timthumb"], $arr[$i]["fulltitle"] , $width, $height, 'thumb'); ?> </a> Any help would be appreciated. Thanks. Link to comment https://forums.phpfreaks.com/topic/213514-detect-file-extension-in-if-statment/ Share on other sites More sharing options...
ignace Posted September 15, 2010 Share Posted September 15, 2010 remove the backticks you don't need them in this particular instance. Link to comment https://forums.phpfreaks.com/topic/213514-detect-file-extension-in-if-statment/#findComment-1111463 Share on other sites More sharing options...
kevinh81 Posted September 15, 2010 Author Share Posted September 15, 2010 Thanks for the quick reply. I removed the backticks... then it was saying Unexpected ";" - after the variables... so i removed them... and now I get Unexpected T_VARIABLE for the line below $ext = pathinfo($file, PATHINFO_EXTENSION) So I guess I just don't really even know if my equation makes sense all together or not. If anyone can provide further help with this, thanks. Link to comment https://forums.phpfreaks.com/topic/213514-detect-file-extension-in-if-statment/#findComment-1111469 Share on other sites More sharing options...
kevinh81 Posted September 16, 2010 Author Share Posted September 16, 2010 Does anyone at least have a suggestion... or knowledge if I'm even approaching this correctly? Thanks. Link to comment https://forums.phpfreaks.com/topic/213514-detect-file-extension-in-if-statment/#findComment-1111532 Share on other sites More sharing options...
kevinh81 Posted September 16, 2010 Author Share Posted September 16, 2010 Is this a better approach? I feel like I'm a lot closer. <?php $filename = $arr[$i]["thumb"]; $file_extension = substr($filename , strrpos($filename , '. ') +1); if (!function_exists('getext')) { function getext() { if($file_extension == 'png') { return 'style="border:none 0 !important;'; } else { null; } } } ?> <a <?php echo getext; ?> href="<?php echo($arr[$i]["permalink"]); ?>" title="<?php printf(__('Permanent Link to %s', 'TheCorporation'), $arr[$i]["fulltitle"]) ?>"> <?php print_thumbnail($arr[$i]["thumb"], $arr[$i]["use_timthumb"], $arr[$i]["fulltitle"] , $width, $height, 'thumb'); ?> </a> But it's just echoing getext.... not actually giving me the return. Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/213514-detect-file-extension-in-if-statment/#findComment-1111564 Share on other sites More sharing options...
kevinh81 Posted September 16, 2010 Author Share Posted September 16, 2010 I think one of my problems is that I don't think I'm pulling the image url properly... can anyone check this? These are some variables in the file $arr[$i]["title"] = truncate_title(50,false); $arr[$i]["title_small"] = truncate_title(25,false); $arr[$i]["fulltitle"] = truncate_title(250,false); $arr[$i]["excerpt"] = truncate_post(470,false); $arr[$i]["excerpt_small"] = truncate_post(80,false); $arr[$i]["tagline"] = get_post_meta($post->ID, 'Tagline', $single = true); $arr[$i]["permalink"] = get_permalink(); $arr[$i]["thumbnail"] = get_thumbnail($width,$height,'thumb',$arr[$i]["fulltitle"],$arr[$i]["tagline"]); $arr[$i]["thumb"] = $arr[$i]["thumbnail"]["thumb"]; $arr[$i]["thumbnail_small"] = get_thumbnail($width_small,$height_small,'',$arr[$i]["fulltitle"],$arr[$i]["tagline"]); $arr[$i]["thumb_small"] = $arr[$i]["thumbnail_small"]["thumb"]; $arr[$i]["use_timthumb"] = $arr[$i]["thumbnail"]["use_timthumb"]; And here again is the original php that calls the image link <a href="<?php echo($arr[$i]["permalink"]); ?>" title="<?php printf(__('Permanent Link to %s', 'TheCorporation'), $arr[$i]["fulltitle"]) ?>"> <?php print_thumbnail($arr[$i]["thumb"], $arr[$i]["use_timthumb"], $arr[$i]["fulltitle"] , $width, $height, 'thumb'); ?> </a> Is anyone able to tell from this which part would return? src="http://image.jpg" Thanks again. Link to comment https://forums.phpfreaks.com/topic/213514-detect-file-extension-in-if-statment/#findComment-1111573 Share on other sites More sharing options...
ignace Posted September 16, 2010 Share Posted September 16, 2010 $file = print_thumbnail($arr[$i]["thumb"]); // you forgot a ) $ext = pathinfo($file, PATHINFO_EXTENSION); Link to comment https://forums.phpfreaks.com/topic/213514-detect-file-extension-in-if-statment/#findComment-1111606 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.