[resolved] A different image on each Page (4 posts)

  1. buskerdog
    Posted 8 years ago #

    I'm sure this can be made to work: I want to call up an image with this:

    'http://www.mydomain.com/images/<?php the_title(); ?>_image.jpg'

    ...and name my images specifically for each page. (home_image.jpg, contact_image.jpg, etc...)

    It works for pages with one name titles but I can't get it to use the Page Slugs over the Page Titles, so Pages with titles like "The Author" don't work. I've tried replacing the_title with a lot of other stuff but nothing works. What's needed? Thanks!

  2. buskerdog
    Posted 8 years ago #

    Alright, I set up Permalinks and I think it's working now...

    EDIT: It's not. Even with Permalinks in effect it doesn't work. Is there no code to use the Page Slug in a way like that?

  3. PozHonks
    Posted 8 years ago #

    The page slug is for "internal" use only, say for Permalinks. It is not hard coded.
    Instead, use the ID of the Page with this command: <?php the_ID(); ?>
    But, in order to work, this tag must be within The Loop.

  4. buskerdog
    Posted 8 years ago #

    Thanks. If I name the image files like 1_image.jpg then that works. Not quite as elegant as what I wanted but it'll do.

Topic Closed

This topic has been closed to new replies.

About this Topic