Support » Themes and Templates » photo link based on page slug

  • Resolved abeolson


    I am creating a custom theme, and still pretty new at this. I’d like to get it set so that a photo appears on the side of the main content. I would like that photo to be pulled from a set of photos, and the pulled photo would correspond to the page slug url.

    Essentially, in the page.php file, I would have

    <img src=” <template URL>/images/<page-slug-name>.jpg”>

    How do I call the template URL and page-slug-name? Also, in case there isn’t a photo for that slug name, could I have a default photo that would be inserted? How would that be done?


Viewing 2 replies - 1 through 2 (of 2 total)
  • eventually figured it out:

    src=”<?php bloginfo(‘template_url’); ?>/images/pagephotos/<?php single_post_title(); ?>.jpg”

    Had to use the post title instead of slug, but it works.

    <?php echo $post->post_name; ?>

    This outputs the slug…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘photo link based on page slug’ is closed to new replies.