WordPress.org

Support

Support » Plugins and Hacks » How to display random icon in post title?

How to display random icon in post title?

  • Caveat: I searched for this but found no info.

    I want to create a dozen or so little (30×30) 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?

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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.

    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.

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

    Are you running wp-cache?

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to display random icon in post title?’ is closed to new replies.
Skip to toolbar