b Posted November 28, 2009 Share Posted November 28, 2009 Not sure how to work this. I essentially want to call a variety of image sizes based on which stylesheet a user chooses from the administration backend of a wordpress theme. The sizes of the images would be different depending on which stylesheet is selected. My idea is to write an if/else statement to accomplish this, but don't know how. The script looks like this: <?php // This will show the image and link the image to the post. Alter the width and height (in both places) to your needs. ?> <?php if ( get_post_meta($post->ID, 'thumb', true) ) { ?> <div class="postthumb"> <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo get_post_meta($post->ID, "thumb", $single = true); ?>&h=180&w=200&zc=1" alt="<?php the_title(); ?>" width="200" height="180" /></a> </div> <?php } ?> If the user selects a layout utilizing a 200px wide image this script would work, but if they choose a layout using a 300px width image the Tim Thumb script would have to be obviously different. Basically, I would like to offer a different Tim Thumb script based on whatever layout/stylesheet the user selects. And I think the best way is to offer an if/else statement, but I don't know how to do this... Any help would be greatly appreciated... Thanks! Quote Link to comment Share on other sites More sharing options...
dragon_sa Posted November 28, 2009 Share Posted November 28, 2009 if I am correct, you appear to be sending the size variable for your images to timthumb.php h=180&w=200 if u change it to h=$newHeight&w=$=$newWidth and delete width="200" height="180" as I believe the script does the image sizing for you you can then define $newWidth and $newHeight then based on the style sheet selected and no need to change timthumb.php at all Quote Link to comment Share on other sites More sharing options...
b Posted November 28, 2009 Author Share Posted November 28, 2009 Sounds like it could work. Let me give it a try, and I'll let you know. Thanks! Quote Link to comment Share on other sites More sharing options...
b Posted November 28, 2009 Author Share Posted November 28, 2009 Not sure how to define $newWidth and $newHeight based on the style sheet ... Quote Link to comment Share on other sites More sharing options...
dragon_sa Posted November 28, 2009 Share Posted November 28, 2009 you could append them directly to the link that changes the stylesheet itself, if you use a form make them hidden variables, if you use a href link put them on the end depends how you r changing the stylesheet, then its just a matter of declaring the sizes you want for each style sheet type Quote Link to comment Share on other sites More sharing options...
b Posted November 28, 2009 Author Share Posted November 28, 2009 Thanks...I'm calling the css stylesheet in the header like this: <?php if ($mp_960 == "true") {?> <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/960.css" type="text/css" media="screen,projection" /> <?php }?> This is if the user selects the 960px width option. Not sure where to put that variable, however Sorry for the noob questions Quote Link to comment Share on other sites More sharing options...
dragon_sa Posted November 28, 2009 Share Posted November 28, 2009 I am assuming you have an if statement for each of those style sheets, just add the 2 variables there in each section for the coresponding size so if mp_960 is supposed to have image 200w and 180h would be <?php if ($mp_960 == "true") { $newHeight="180"; $newWidth="200"; ?> <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/960.css" type="text/css" media="screen,projection" /> <?php }?> so when that if statement is true so to are the settings for your timthumb script Quote Link to comment Share on other sites More sharing options...
b Posted November 28, 2009 Author Share Posted November 28, 2009 Seems like that should work, but it doesn't. Here's what I have in the header: <?php if ($mp_960 == "true") { $newHeight="180"; $newWidth="470"; ?> <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/960.css" type="text/css" media="screen,projection" /> <?php }?> And here is what I have in the index.php <!-- Start Tim Thumb --> <?php // This will show the image and link the image to the post. Alter the width and height (in both places) to your needs. ?> <?php if ( get_post_meta($post->ID, 'thumb', true) ) { ?> <div class="postthumb"> <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo get_post_meta($post->ID, "thumb", $single = true); ?>&h=$newHeight&w=$=$newWidth&zc=1" alt="<?php the_title(); ?>" /></a> </div> <?php } ?> <!-- End Tim Thumb --> And here is what I believe is the relevant code in Tim Thumb // get properties $new_width = preg_replace("/[^0-9]+/", "", get_request("w", 0)); $new_height = preg_replace("/[^0-9]+/", "", get_request("h", 0)); $zoom_crop = preg_replace("/[^0-9]+/", "", get_request("zc", 1)); $quality = preg_replace("/[^0-9]+/", "", get_request("q", 80)); $filters = get_request("f", ""); if ($new_width == 0 && $new_height == 0) { $new_width = 200; $new_height = 180; } Confused why that didn't work...Seems like you were right, but something must be missing. Thanks again Quote Link to comment Share on other sites More sharing options...
dragon_sa Posted November 29, 2009 Share Posted November 29, 2009 The variable need to be in the php for them to change from the variable name to the variable, also you have a typo. you have <img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo get_post_meta($post->ID, "thumb", $single = true); ?>&h=$newHeight&w=$=$newWidth&zc=1" alt="<?php the_title(); ?>" /> it should be like this <img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo get_post_meta($post->ID, "thumb", $single = true); ?>&<?php echo "h=".$newHeight."&w=".$newWidth; ?>&zc=1" alt="<?php the_title(); ?>" /> See how that goes Quote Link to comment Share on other sites More sharing options...
b Posted November 29, 2009 Author Share Posted November 29, 2009 well...I'm clearly a nuisance at this point. but it doesn't seem to work. however, the tim thumb script does seem to be resizing the image to be 200px wide and 180px height. how it's doing this is, to me, unclear. here is the testing url I'm using to figure this out: http://www.minimlpress.com/ the idea is to allow the user the option to choose a different style sheet for their site. if they choose the 960px width style sheet I wanted the images to resize to 470px, thus showing two columns. I'm calling the tim thumb script like this: <!-- Start Tim Thumb --> <?php if ( get_post_meta($post->ID, 'thumb', true) ) { ?> <div class="postthumb"> <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo get_post_meta($post->ID, "thumb", $single = true); ?>&<?php echo "h=".$newHeight."&w=".$newWidth; ?>&zc=1" alt="<?php the_title(); ?>" /></a></div> <?php } ?> <!-- End Tim Thumb --> And in the header it looks like this: <?php if ($mp_960 == "true") { $newHeight="180"; $newWidth="470"; ?> <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/960.css" type="text/css" media="screen,projection" /> <?php }?> It is calling properly the style sheet, but the image is not resizing to 470px. Not sure why. If I'm being annoying, I apologize. thanks again Quote Link to comment Share on other sites More sharing options...
dragon_sa Posted November 29, 2009 Share Posted November 29, 2009 <img src="http://www.minimlpress.com/wp-content/themes/_minpress/scripts/timthumb.php?src=http://www.minimlpress.com/i/jasmine.jpg&h=&w=&zc=1" alt="jasmine" /> is what it is printing in the browser on loading the page which has no variable set for h & w so the timthumb script sets it to 200 & 180 if ($new_width == 0 && $new_height == 0) { $new_width = 200; $new_height = 180; } I cant see where your changing the style sheet for this page but looking at that url echo the $newWidth & $newHeight variable tpwards the top of your page that changes the style sheet and see if the variables are getting set Quote Link to comment Share on other sites More sharing options...
b Posted November 29, 2009 Author Share Posted November 29, 2009 I echoed: <?php echo $newHeight ?> <?php echo $newWidth ?> and got: 180 & 470 does it matter that the variables in the tim thumb script are : $new_width and $new_height and not $newWidth and $newHeight? I tried it but it didn't make a difference...just wondering Quote Link to comment Share on other sites More sharing options...
dragon_sa Posted November 29, 2009 Share Posted November 29, 2009 putting this in your url works http://www.minimlpress.com/wp-content/themes/_minpress/scripts/timthumb.php?src=http://www.minimlpress.com/i/b.jpg&h=180&w=460&zc=1 but the code your page is generating is this with no values for w and h <img src="http://www.minimlpress.com/wp-content/themes/_minpress/scripts/timthumb.php?src=http://www.minimlpress.com/i/b.jpg&h=&w=&zc=1" alt="b on bed" /> so the problem is happening somehow sending the variables to your image links the $new_width variable is independent of $newWidth variable and does not affect each other directly Quote Link to comment Share on other sites More sharing options...
jay7981 Posted November 29, 2009 Share Posted November 29, 2009 try changing $new_width = preg_replace("/[^0-9]+/", "", get_request("w", 0));$new_height = preg_replace("/[^0-9]+/", "", get_request("h", 0)); to $new_width = preg_replace("/[^0-9]+/", "", get_request("w", ""));$new_height = preg_replace("/[^0-9]+/", "", get_request("h", "")); Quote Link to comment Share on other sites More sharing options...
dragon_sa Posted November 29, 2009 Share Posted November 29, 2009 I dont beleive the problem is in the timthumb.php script, you can see by the html output above that the variables are not being echoed to h & w in the src link could I see all the page that generates this? Quote Link to comment Share on other sites More sharing options...
b Posted November 29, 2009 Author Share Posted November 29, 2009 Sure. Here's the index.php <?php get_header(); ?> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div class="gallery"> <div <?php post_class() ?> id="post-<?php the_ID(); ?>"> <!-- the title --> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <!-- the date --> <p><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></p> <!-- Start Tim Thumb --> <?php if ( get_post_meta($post->ID, 'thumb', true) ) { ?> <div class="postthumb"> <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo get_post_meta($post->ID, "thumb", $single = true); ?>&<?php echo "h=".$newHeight."&w=".$newWidth; ?>&zc=1" alt="<?php the_title(); ?>" /></a></div> <?php } ?> <!-- End Tim Thumb --> <!-- the Content --> <?php the_content('Read the rest of this entry »'); ?> <!-- the Tags & Comments --> <p><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p> </div> </div> <?php endwhile; ?> <!-- else --> <?php else : ?> <h2>Not Found</h2> <p>Sorry, but you are looking for something that isn't here.</p> <?php get_search_form(); ?> <?php endif; ?> <!-- end else --> <?php get_footer(); ?> Here's the head section: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>> <!-- Admin Options --> <? global $options; foreach ($options as $value) { if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); } } ?> <head profile="http://gmpg.org/xfn/11"> <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" /> <title><?php wp_title('«', true, 'right'); ?> <?php bloginfo('name'); ?></title> <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" /> <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" /> <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?>" href="<?php echo $mp_feedburner; ?>" /> <?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?> <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/global.css" type="text/css" media="screen,projection" /> <!-- Layout Options --> <?php if ($mp_720 == "true") {?> <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/720.css" type="text/css" media="screen,projection" /> <?php }?> <?php if ($mp_840 == "true") {?> <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/840.css" type="text/css" media="screen,projection" /> <?php }?> <?php if ($mp_960 == "true") { $newHeight="180px"; $newWidth="470px"; ?> <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/960.css" type="text/css" media="screen,projection" /> <?php }?> <?php if ($mp_dark == "true") {?> <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/dark.css" type="text/css" media="screen,projection" /> <?php }?> <?php if ($mp_two_column == "true") {?> <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/two-column.css" media="screen,projection" /> <?php }?> <?php if ($mp_two_column_wide == "true") {?> <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/two-column-wide.css" type="text/css" media="screen,projection" /> <?php }?> <!-- Comments Script Thanks to Chris Coyier from CSS-Tricks --> <SCRIPT TYPE="text/javascript"> function setbg(color) { document.getElementById("comment").style.background=color } </SCRIPT> <?php wp_head(); ?> </head> Not sure if would help to see this code but here is the theme option in the functions.php: array( "name" => __('960px'), "desc" => __("960px Width"), "id" => $shortname."_960", "std" => "false", "type" => "checkbox"), Quote Link to comment Share on other sites More sharing options...
dragon_sa Posted November 29, 2009 Share Posted November 29, 2009 In the head section change $newHeight="180px"; $newWidth="470px"; to $newHeight="180"; $newWidth="470"; the script is looking for a number so by putting px next to it that number is effectively 0 prompting the default size Quote Link to comment Share on other sites More sharing options...
dragon_sa Posted November 29, 2009 Share Posted November 29, 2009 also on the index page echo $newWidth and $newHeight straight after this div <div class="postthumb"> so we can see if the variables still exist in the correct spot Quote Link to comment Share on other sites More sharing options...
b Posted November 29, 2009 Author Share Posted November 29, 2009 It only seems to be echoing in the header section from this: <?php if ($mp_960 == "true") { $newHeight="180"; $newWidth="470"; ?> <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/960.css" type="text/css" media="screen,projection" /> <?php }?> When I echo <?php echo $newHeight ?> and <?php echo $newWidth ?> it doesn't appear anywhere - perhaps I'm doing that incorrectly? Quote Link to comment Share on other sites More sharing options...
dragon_sa Posted November 29, 2009 Share Posted November 29, 2009 try this in the head section <?php if ($mp_960 == "true") { $newHeight="180"; $newWidth="470"; global $newHeight, $newWidth; ?> <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/960.css" type="text/css" media="screen,projection" /> <?php }?> Quote Link to comment Share on other sites More sharing options...
b Posted November 29, 2009 Author Share Posted November 29, 2009 Unfortunately, it didn't work. I tried to echo <?php echo $newWidth ?> and it didn't show up... Quote Link to comment Share on other sites More sharing options...
dragon_sa Posted November 30, 2009 Share Posted November 30, 2009 Whats happening is the variable is being declared inside the function, it needs to be declared as a global variable for use outside the header function I might of had it the wrong way around but try putting the global line above the 2 variables and see if that changes it, may need to declare them as globals before assigning them. Quote Link to comment Share on other sites More sharing options...
b Posted November 30, 2009 Author Share Posted November 30, 2009 Brilliant! It works great...http://www.minimlpress.com/ - (just a testing ground) You've been very helpful, and I'm going to give you full credit in the development of this theme! I've learned a lot in this process. Very much appreciated. Quote Link to comment Share on other sites More sharing options...
dragon_sa Posted November 30, 2009 Share Posted November 30, 2009 Not a problem glad we finally got there Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.