Welcome to Welcome to DNF.com™ - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars

If you are new to domains and looking to buy, sell and learn about domains then you have come to the right place. DNForum is the largest domain name community on the internet and continues to grow every day. There are over 105,000 domainers on DNForum doing everything from buying domains, selling domains, learning about domains and discussing domains. Take a minute and Register.

Register Today on DNForum IT'S FREE!

Results 1 to 4 of 4
  1. #1
    Platinum Lifetime Member
    kokopelli's Avatar
    Join Date
    Jul 2004
    Location
    USA
    Posts
    1,062
    DNF$
    5,254
    Bank
    0
    Total DNF$
    5,254
    Donate  

    Question How to display a random image in this code?

    Hope one of you PHP gurus can help me ...

    In a WordPress theme, I want to change this code:
    Code:
    <?php if ( function_exists( 'get_the_image' ) ) { get_the_image(array( 'default_size' => 'thumbnail', 'image_scan' => true, 'default_image' => get_bloginfo( 'template_url' ) . '/images/default_thumbnail.png', 'width' => '100', 'image_class' => 'wp-post-image' )); } ?>
    to something like
    Code:
    <?php if ( function_exists( 'get_the_image' ) ) { get_the_image(array( 'default_size' => 'thumbnail', 'image_scan' => true, 'default_image' => get_bloginfo( 'template_url' ) . '/images/default_thumbnail_0<?php echo rand(1,3)?>.png', 'width' => '100', 'image_class' => 'wp-post-image' )); } ?>
    so a random image between 1 and 3 is displayed as thumbnail.

    But my code doesn't work ... no image is displayed

    Any idea how I should change it?

  2. #2
    Platinum Lifetime Member
    kithkanan's Avatar
    Join Date
    Feb 2010
    Location
    Iloilo
    Posts
    318
    Country

    Philippines
    DNF$
    1,604
    Bank
    0
    Total DNF$
    1,604
    Donate  
    I think putting it inside the <?php ?> block is not right. Try to put it in a variable first then concatenate. Try something like this one:

    <?php $randomImg = rand(1,3);?>

    <?php if ( function_exists( 'get_the_image' ) ) { get_the_image(array( 'default_size' => 'thumbnail', 'image_scan' => true, 'default_image' => get_bloginfo( 'template_url' ) . '/images/default_thumbnail_0'. $randomImg .'.png', 'width' => '100', 'image_class' => 'wp-post-image' )); } ?>

  3. #3
    Platinum Lifetime Member
    kokopelli's Avatar
    Join Date
    Jul 2004
    Location
    USA
    Posts
    1,062
    DNF$
    5,254
    Bank
    0
    Total DNF$
    5,254
    Donate  
    Cool, that works (I had to put variable in the WordPress functions file).

    Thanks!

  4. #4
    Platinum Lifetime Member
    kithkanan's Avatar
    Join Date
    Feb 2010
    Location
    Iloilo
    Posts
    318
    Country

    Philippines
    DNF$
    1,604
    Bank
    0
    Total DNF$
    1,604
    Donate  
    np

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Domain name forum recommended by Domaining.com