Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Conditional Timthumb image slider help WordPress

  • SOLVED

Hi, I am working on a clients site, I did not write the code for.

The home page displays an image slider of the latest posts using timthumb, it displays only on the homepage.

But... the site is multilingual, using the WPML plug-in, and it creates a dynamic translated version by directory.

for instance main site is:
www.the..site.com
www.the..site.com/fr ( dynamic translated version for French)


The timthumb slide show does not show on any of translated home pages.

The code showing the slider is custom and I cannot understand it well enough to also add a conditional for a directory like /fr or /es .

<a class="preview" href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php $th_url = (get_post_meta($post->ID, "post_image_value", $single = true)) ? $urlHome . "/scripts/timthumb.php?src=".get_post_meta($post->ID, "post_image_value", $single = true)."&amp;w=".get_option('cb_featured_posts_width')."&amp;h=".get_option('cb_featured_posts_height')."&amp;zc=1" : $urlHome ."/images/th_80x80.jpg"; ?><img alt="<?php the_title(); ?>" src="<?php echo $th_url; ?>" width="<?php echo get_option('cb_featured_posts_width'); ?>" height="<?php echo get_option('cb_featured_posts_height'); ?>" />



I have already tried inserting a language based conditional such as <?php if(ICL_LANGUAGE_CODE=='fr'): ?> do whatever... It does work but not for the above code, as I am sure it has something to do with the post-->ID and url.


Any thoughts?, I can supply more code, I kept it simple.

**UPDATE

Thanks guys but none of the suggestions have worked, here is the whole code maybe it will help

http://pastebin.com/RuTFMzXP



**UPDATE 2


After reading the comments and looking into further it looks like this is a javascript or css problem, will update what I find.


**Update 3 it now works

Answers (5)

2010-10-14

Ashfame answers:

I think on other places its looking for the timrhumb script at the wrong location.

If you see your code, then you need to fix this part

<?php $th_url = (get_post_meta($post->ID, "post_image_value", $single = true)) ? $urlHome . "/scripts/timthumb.php

$urlHome changes its value, I guess.

So try by hitting the absolute value of the timthumb script here (where it actually works) instead of the variable content.


Ashfame comments:

Can you tell us the URL for an image that work and for one that doesn't?


Bob comments:

A working url on the main site ..com is http://www.the..site.com/blog/wp-content/themes/Theme/scripts/timthumb.php?src=http://www.the..site.com/blog/wp-content/uploads/2010/02/golf.jpg&w=280&h=180&zc=1


The slider does not show up on the /fr version so there is no url.


Ashfame comments:

If the silder doesn't show up, then its not the timthumb problem (atleast not now), what everyone here is trying to solve. Its your javascript issue.

Can you paste the concerned js? Also check if any js errors are being produced


Ashfame comments:

the problem is with the js code you are using. right now it only contains two posts and the left margin is way too much which means it is outside the view and since it contains only two images, the margin doesn't change that much to show either of them.
And then it iterates in the loop again.
When you have more number of posts, they will start showing up by themself.
Either you fix it for working with smaller number of images or just let more posts come in and it will work :)


Bob comments:

Yes this is correct.


Ashfame comments:

Told ya! ;)

You can stop worrying about it as the posts are only going to increase with time and not falling below the threshold of showing them :)

2010-10-14

Baki Goxhaj answers:

Seems like the guy has hard-coded the home timthumb url with only the homepage url being dynamic.

Try this code:


<a class="preview" href="<?php the_permalink() ?>" title="<?php the_title(); ?>">

<?php $urlHome = get_bloginfo('template_url'); ?>

<?php $th_url = (get_post_meta($post->ID, "post_image_value", $single = true)) ? $urlHome . "/scripts/timthumb.php?src=".get_post_meta($post->ID, "post_image_value", $single = true)."&amp;w=".get_option('cb_featured_posts_width')."&amp;h=".get_option('cb_featured_posts_height')."&amp;zc=1" : $urlHome ."/images/th_80x80.jpg"; ?>

<img alt="<?php the_title(); ?>" src="<?php echo $th_url; ?>" width="<?php echo get_option('cb_featured_posts_width'); ?>" height="<?php echo get_option('cb_featured_posts_height'); ?>" />


Bob comments:

Thanks please see update for pastbin link, maybe it will help.


Baki Goxhaj comments:

Remove this pieces of code and leave only the code I provided you with.

<?php elseif(ICL_LANGUAGE_CODE=='en'): ?>
<?php if(ICL_LANGUAGE_CODE=='fr'): ?>


Bob comments:

Did not work, main site works like usual /fr home page shows nothing.


Baki Goxhaj comments:

Can you provide me with a link of the website? I need to have a look at the code on the FR version.


Baki Goxhaj comments:

What is the alternative if this in the Fr version:

<em> http://www.the..site.com/blog/wp-content/themes/Theme/scripts/timthumb.php?src=http://www.the..site.com/blog/wp-content/uploads/2010/02/golf.jpg&w=280&h=180&zc=1</em>


Baki Goxhaj comments:

Go your message - looking at it now


Bob comments:

Please re-check I took out the dummy slider (meteor slider) I was using as a test.


Bob comments:

It now works thanks to this code, the javascript was fine I just needed to populate the /fr page with more posts.

2010-10-14

Pippin Williamson answers:

Which part of the slider doesn't work? Do the images not show up? Does the jQuery not load?

A few more details, please.


Bob comments:

The slider does not load at all.


Pippin Williamson comments:

Instead of checking for what the current language is, check for the current URL and see if that works. Perhaps the language variable is failing for some reason.

You can get the current url with this:

<?php
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>


The do the IF check like this:


if ( curPageURL() == get_bloginfo('url') . '/fr/' )
{
//french slider code here
}
else
{
// english slider code here
{


You will need to make sure that the urls match EXACTLY. For example, curPageURL may append a '/' to the end of the url, while get_bloginfo('url'), might not.

In order to double check that, use a PHP echo statement on each:


echo curPageURL() . '\n';
echo get_bloginfo('url');


and see if they match. If not, the adjust accordingly.


Bob comments:

Yes this was is my last option, it would probably work but I think there must be a better solution.


The language variable does work, for instance I had put a differant slider in there and it works fine ( metoer slider) to test it.

<?php if(ICL_LANGUAGE_CODE=='fr'): ?>
<?php if(function_exists('meteor_slideshow')) { meteor_slideshow(); } ?>
<?php elseif(ICL_LANGUAGE_CODE=='en'): ?>
old slider code here


The above works fine, it just I want to use the same slider.


Pippin Williamson comments:

Ok. So which part of the slider doesn't load? The images? the jQuery? It's most likely a problem with file paths.


Bob comments:

Actually I just realized th images are showing in the source.

The /fr source
<a
class="preview" href="http://www.t.com/blog/fr/?p=422" title="title"><img
alt="" src="http://www.t.com/blog/wp-content/themes/Theme/scripts/timthumb.php?src=http://www.tr.com/blog/wp-content/uploads/2010/10/cessna.jpg&amp;w=280&amp;h=180&amp;zc=1" width="280" height="180" /> </a>


the main page source <a
class="preview" href="http://www.tremblantplatinum.com/blog/?p=86" title="8 last minute ways to save for your vacation"><img
alt="8 last minute ways to save for your vacation" src="http://www.tremblantplatinum.com/blog/wp-content/themes/NatTheme/scripts/timthumb.php?src=http://www.tremblantplatinum.com/blog/wp-content/uploads/2010/02/golf.jpg&amp;w=280&amp;h=180&amp;zc=1" width="280" height="180" /> </a>

2010-10-14

Maor Barazany answers:

Does the image is the same for all languages or each language has its own version of an image?

If image is the same for all, try this:

<?php $th_url = (get_post_meta($post->ID, "post_image_value", $single = true)) ? get_bloginfo('url') . "/scripts/timthumb.php?src=".get_post_meta($post->ID, "post_image_value", $single = true)."&amp;w=".get_option('cb_featured_posts_width')."&amp;h=".get_option('cb_featured_posts_height')."&amp;zc=1" : get_bloginfo('url') ."/images/th_80x80.jpg"; ?><img alt="<?php the_title(); ?>" src="<?php echo $th_url; ?>" width="<?php echo get_option('cb_featured_posts_width'); ?>" height="<?php echo get_option('cb_featured_posts_height'); ?>" />


If it is not working, try to put the domain name statically :

<?php $th_url = (get_post_meta($post->ID, "post_image_value", $single = true)) ? "http://www.domain.com" . "/scripts/timthumb.php?src=".get_post_meta($post->ID, "post_image_value", $single = true)."&amp;w=".get_option('cb_featured_posts_width')."&amp;h=".get_option('cb_featured_posts_height')."&amp;zc=1" : "http://www.domain.com" ."/images/th_80x80.jpg"; ?><img alt="<?php the_title(); ?>" src="<?php echo $th_url; ?>" width="<?php echo get_option('cb_featured_posts_width'); ?>" height="<?php echo get_option('cb_featured_posts_height'); ?>" />


Just replace the two places with <strong>http://www.domain.com</strong> with the real domain name.

If for each language you should use another image, it's more complicated to achieve.


Hope it helps..


Bob comments:

Thanks but I have put up the full code here as this also does not work and I had previously tried it.

http://pastebin.com/RuTFMzXP

2010-10-14

Nilesh shiragave answers:

can you try replacing &amp; with just & like

from following lines in your code


<?php $th_url = (get_post_meta($post->ID, "post_image_value", $single = true)) ? $urlHome . "/scripts/timthumb.php?src=".get_post_meta($post->ID, "post_image_value", $single = true)."&amp;w=".get_option('cb_featured_posts_width')."&h=".get_option('cb_featured_posts_height')."&zc=1" : $urlHome ."/images/th_80x80.jpg"; ?>