spiritbased
Member
Posted 5 years ago #
Hi all,
Can I use the is_page conditional tag to include a different, specific image in each of my Pages?
In english ('cos I don't speak PHP) "if this page is 'about' then include about.jpg"?
I'd like the image to appear above the page title.
If this is possible, could someone please show me how the code should be syntaxed?
thanks!
The simplest (?) way to do this would be to make a variety of page templates. Each more or less identical aside from the image.
Check out Pages for more on that.
Ok.. actually, is_page oughta work just fine based on what's written here: Conditional_Tags
spiritbased
Member
Posted 5 years ago #
Okay, thanks... but I don't know how to write the code snippet. Would it be something like
<?php
if(is_page(about))
{
<img src=image.jpg>
}
Sorry but it seems my question is a simple one of syntax...
In the middle of this example
http://codex.wordpress.org/Conditional_Tags#Variable_Sidebar_Content
you can see how does it work with several Pages.
spiritbased
Member
Posted 5 years ago #
Okay, I sniffed around on the forums some more and got this working;
<?php if (is_page(11)) : ?>
<p>I want my image here</p>
<?php endif; ?>
And the text appears exactly where I want the image. My question is, what should I replace the middle line with to get my image up instead?
spiritbased
Member
Posted 5 years ago #
My images folder is in the same directory as my page.php file, so you'd think that...
<?php if (is_page(11)) : ?>
<img src="images/image.jpg">
<?php endif; ?>
...would work, non? But it doesn't!
Am I completely wrong, or can I just not see the wood for the trees here?
It won't work because without a full path to the images/ directory, your web browser will expect to find it in the current one it is at, and not the one the template is in. You could hard code the *full* url to your images/ directory, or try this:
<?php if (is_page(11)) : ?>
<img src="<?php bloginfo('template_directory'); ?>/images/image.jpg">
<?php endif; ?>
spiritbased
Member
Posted 5 years ago #
Pardon my newbieness, but does that mean ('template_directory') should be entered verbatim? or do i put a path in there?
Thanks for bearing with me!
Yes, enter it exactly as I wrote it. It's a bit of WordPress/PHP code that should output the url for the current template (that is, theme) directory. See here for info:
http://codex.wordpress.org/Template_Tags/bloginfo
spiritbased
Member
Posted 5 years ago #
Cool! it works - I'm over the moon here!
Now - is there any way to use the same command to add a specific image to category and archive pages?
Yes, you go back to that Conditional Tags page in the Codex... and you will see all the possible tags, like:
is_category() or is_category(XY) or is_archive etc.
Replace the "is_page()" part with what you need.
spiritbased
Member
Posted 5 years ago #
Nice one - the help on these forums is priceless.