I would use: 

in_category('cat-slug') ) { 


if you want to display the image on all posts in the category.

Here's a working example i wrote and tested.

This returns true on both the category archive page and all posts in the category

if(is_home())

echo '&lt;div class="home-header"&gt;&lt;img src="http://yourdomain.com/path/to/image.png" alt="category header image" /&gt;&lt;/div&gt;';

elseif(in_category('category-1') )

echo '&lt;div class="category-one-header"&gt;&lt;img src="http://yourdomain.com/path/to/image.png" alt="category header image" /&gt;&lt;/div&gt;';

elseif(in_category('category-2') )

echo '&lt;div class="category-two-header"&gt;&lt;img src="http://yourdomain.com/path/to/image.png" alt="category header image" /&gt;&lt;/div&gt;';

elseif(in_category('category-3') )

echo '&lt;div class="category-three-header"&gt;&lt;img src="http://yourdomain.com/path/to/image.png" alt="category header image" /&gt;&lt;/div&gt;';

elseif(in_category('category-4') )

echo '&lt;div class="category-four-header"&gt;&lt;img src="http://yourdomain.com/path/to/image.png" alt="category header image" /&gt;&lt;/div&gt;';

}


Related info

Another option would be to use the code from the Twenty Eleven themes header.php file which enables you to use the built in Add Featured Image meta box to display unique headers on different posts and pages without adding any code.

Or you could easily add conditionals and else if statements to that code which is a more efficient solution.

Why isn't my if/elseif/else working correctly here?
I am having a Database.
The size of my database is near about 4GB(Only .mdf file).
In that database only few tables present which have the maximum data of database. One of them and the biggest table is Table1. This is a huge table means everyday near about 80000 data inserted and same no. of records deleted. There are 30 days * 80000 records present in that table. This table is used very frequently. Hence it takes time to query large data. So my development team decided to create Partition of same table. Table11 has four columns in primary key. 
Primary Key Columns :


ChequeDate Date
RunNo Int
SorterNo Int
SequenceNo Int


We decided to partition the table on the basis of SequenceNo column.

I created a partition script and ran it which partitions an existing table. This works perfectly.
Next I run a "rollback" script to remove the partitioning. This also runs perfectly.

When I try to reapply partitioning on the same table it gives me the error mentioned in title. I found a manual solution that worked for me.

My problem is this process should run from a script only. No manual work should be necessary.

I assume that the problem is in the rollback script:

ALTER TABLE [dbo].[Table1] DROP CONSTRAINT [PK_Table1] with (move to [primary]);
DROP PARTITION SCHEME Table1PartSch
DROP PARTITION FUNCTION Table1PartFunc

ALTER DATABASE [MyDataBase] REMOVE FILE Table125LData;
ALTER DATABASE [MyDataBase] REMOVE FILE Table117LData;
ALTER DATABASE [MyDataBase] REMOVE FILE Table17LData;
ALTER DATABASE [MyDataBase] REMOVE FILE Table12LData;
ALTER DATABASE [MyDataBase] REMOVE FILE Table1RestData;
GO
ALTER DATABASE [MyDataBase] REMOVE FILEGROUP Table125LFG;
ALTER DATABASE [MyDataBase] REMOVE FILEGROUP Table117LFG;
ALTER DATABASE [MyDataBase] REMOVE FILEGROUP Table17LFG;
ALTER DATABASE [MyDataBase] REMOVE FILEGROUP Table12LFG;
ALTER DATABASE [MyDataBase] REMOVE FILEGROUP Table1RestFG;
GO




If someone have better solution other than Partitioning, to this situation is Welcome.
