views:

275

answers:

2

Hi all,

I'm trying to have different pictures on every one of my pages built on wordpress.

So I have the following in my index.php file, archive.php file, page.php file, etc:

<img src="<?php bloginfo('template_url'); ?>/images/<?php echo $toppic; ?>" alt="page1" id="mainPageImg" />

Now, in my page.php file, I have the following:

<?php
    // TOP PICTURE DEFINITIONS
    if ( is_home() ) {
        $toppic == 'page1.png';
    }
    if ( is_page('articles') ) {
        $toppic == 'page2.png';
    }
?>

How come this does not work? I tried it with one equal (=) sign...

EDIT: If I define $toppic at the top, for example, in the index.php file as follows:

<?php $toppic = 'page1.png'; ?>

Then it works. So therefore, it must be something that has to do with the conditional if is_page/is_home statements. Any ideas?

Thanks! Amit

+1  A: 

The slug for your Articles page has to be defined as articles. This is set in the edit page interface, see these directions.

Jesse Dhillon
Yeah true. I'll look into that
Amit
Shouldn't is_home() work as well though?
Amit
I just checked it, the slug is set for articles...I should mention that this is a child page of a parent page. Should that matter?
Amit
All of the other pages now work except the blog (articles) page
Amit
I even tried to do is_page('53') where '53' is the ID of the articles (blog) page. How-come this doesn't work but all others do!$@!$
Amit
+2  A: 

Okay, I found the answer.

This is what needs to be done. For the articles (blog) page, at the top section you need to place the following:

<?php // TOP PICTURE DEFINITION FOR ARTICLES PAGE
        if ( is_home() ) {
            $toppic = 'page1.png';
        }
?>

Then, in your page.php file, you can control the picture at the top for all other pages (except 404, where you'd need to put a is_404() in your 404.php. So this is what it looks like:

<?php
    // TOP PICTURE DEFINITIONS
    if ( is_page('english') ) {
        $toppic = 'page1.png';
    }
    if ( is_page('aboutus') ) {
        $toppic = 'page1.png';
    }
    if ( is_page('newspaper') ) {
        $toppic = 'page1.png';
    }
    else {
        $toppic = 'page1.png';
    }
?>

And finally, in order to implement this, use the following HTML/php syntax:

<img src="<?php bloginfo('template_url'); ?>/images/<?php echo $toppic ?>" alt="page1" id="mainPageImg" />

That's all. Phew. Finally got it to work :) Had to do it for a client, too!

Amit
I'm not getting what the solution was, is your "articles" page also your home page?
Jesse Dhillon
The articles page is not my home page. I have set a 'static' front page. However, Wordpress function is_home() returns 'true' for the blog page (aka my articles page). That's why you have to place is_home() on the index.php file, is_404() on the 404.php file, and is_page() in the page.php file. Hope that helped
Amit
Ok, I thought 'articles' was one of your static pages not your blog page. Yes `is_home()` is the page which is your main blog page and `is_front_page()` is your front page.
Jesse Dhillon
Do you happen to know how to show posts on more than one page?
Amit