How to display random icon in post title? (5 posts)

  1. thebadastronomer
    Posted 9 years ago #

    Caveat: I searched for this but found no info.

    I want to create a dozen or so little (30x30) icons and have one displayed at random in front of each post title. I found several randomizing PHP scripts that'll do it, and I put the code in post.php where the title is displayed:

    <h2 id="post-<?php the_ID(); ?>">
    <img src="imagerand.php">
    <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent link to <?ph
    p the_title();?>"><?php the_title(); ?></a></h2>

    This works, kinda. It displays the icon next to the title, so that's good (example).

    But, I have the latest four posts on my index page. They each get the same icon! I want to have a different icon for each post. I suspect this is some arcane use of The Loop, but I'm not sure how to implement this. Any ideas?

  2. WildBil2Me
    Posted 9 years ago #

    Without seeing the code for imagerand.php it's kind of hard to see, can you provide a link to it changed to a .txt file?

    It looks as though a random number is only being generated once and then assigned multiple times.

  3. thebadastronomer
    Posted 9 years ago #

    I used this code: http://photomatt.net/scripts/randomimage

    I think you might be right, but if the code is called more than once, a different number should be generated (I called the routine several times on its own, and got a different image every time). That's why I suspect the problem is the way the post.php file is called by the loop.

  4. Chris_K
    Posted 9 years ago #

    or... and this is truly a shot in the dark...

    Are you running wp-cache?

  5. thebadastronomer
    Posted 9 years ago #

    Heh. I turn it off when I test things like this. Good guess, though!

Topic Closed

This topic has been closed to new replies.

About this Topic