WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] photo link based on page slug (3 posts)

  1. abeolson
    Member
    Posted 6 years ago #

    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?

    thanks!

  2. abeolson
    Member
    Posted 6 years ago #

    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.

  3. luminancedesign
    Member
    Posted 5 years ago #

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

    This outputs the slug...

Topic Closed

This topic has been closed to new replies.

About this Topic