• hi,

    for my little wordpress-theme i need a little php-script. i am not a programmer and very new to wp so the php-syntax is killing my idea.

    i have a name convention for my pictures. they are stored in the image-folder in my template-directory and named like this: img-"the_title".jpg

    the_title is the wordpress template tag.
    example: img-contact.jpg

    now i need a query that swaps my pictures automatically when i click through my page.

    i have a script fragment of another page but it doesn’t work with wordpress:

    <img src="images/img-<?
        if (file_exists("images/img-".$plink.".jpg")) {
    	  echo $plink.".jpg";
          } else {
    	  echo "img-default.jpg";
        }
    ?>" width=960 height=204 alt="" border=0 hspace=0 vspace=0>

    i need a way to exchange the $plink to the wordpress template tag/function the_title but i have no clue how to get this to work =) i get tons of errors …

    i hope someone can help me with this (… and understand my bad english =)

    thanks,
    le huf

Viewing 1 replies (of 1 total)
  • <?php echo $post->post_name; ?>

    The code above will return the current slug for the page or post, that way you can add images such as img-post-name.jpg to your directory.

    You may also want to use a file_exist command, that way if the image file is not present you can always display a default image.

Viewing 1 replies (of 1 total)
  • The topic ‘need help with php-query for image-swap’ is closed to new replies.