Forum

Thread tagged as: Question, Blog

Archive.php heading based on Category

I want to have a different photo on the top of my archive.php page based on the category i am in.

I originally did this with 2 different blog listing pages (planning.php and news.php) which worked well until I realised the post.php file (via the post_category_link.html template) takes users back to the archive.php?cat=<perch:category id="catSlug" />">

Then I though I would use archive.php?cat=news etc but i think this means i need to put some php code in archive.php along the lines of category=news image1 elseif category=planning image2 else image3

Are either of these the rignt "perch" way to do it or is there a better way. If they are ok, can anyone help me with the code i should add (either to post_category_link.html or to archive.php)

cow shed

cow shed 0 points

  • 7 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

So something like the below would do it if the images are just hardcoded into the page.

<?php
if(perch_get('cat') == 'news') {
  $img = 'image1.jpg';
} elseif (perch_get('cat') == 'planning') {
  $img = 'image2.jpg';
} else {
  $img = 'image3.jpg';
}
?>
<img src="/path/to/<?php echo $img; ?>" />

Thanks so much - I've managed to switch templates now too