I'm trying to produce a somewhat advanced wordpress loop for any new website. I must display all recent posts around the top of the page, but in a different way based on selected category.

I'm thinking something similar to this:

Start Loop

Check if category = category 1

If category = category 1:

<-- Loop elements for said category (template tags etc.) -->

Else, check if category = category 2

If category = category 2 

<-- Loop elements for said category (template tags etc.) -->

Else

<-- Standard loop elements (template tags etc.) -->

End loop

Is possible? Exist simpler ways to get this done? I recognize i possibly could use multiple loops, but want to keep your posts in chronological order.

I attempted while using following code, but this breaks after i place the template tags within the echo?

<?php
$category_name = 'Category 1';
if(in_category($category_name)) {
  echo '

<div class="post">
the_title();
the_excerpt();
<div>

';
}
?>

Any help much appreciated :)

Try

<?php
$category_name = 'Category 1';
if(in_category($category_name)) {
?>

<div class="post">
<?php the_title(); ?>
<?php the_excerpt(); ?>
<div>

<?php
}
?>