开发者

Using different wordpress loop output depending on category

I am trying to create a somewhat advanced wordpress loop for a new website. I would like to display all recent posts on the front page, but differently depending on chosen category.

I am thinking something like 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 this possible? Are there simpler ways to do this? I realize i could use multiple loops, but would like to keep the posts in chronological order.

I tried using the following code, but this breaks when i put the template tags in the echo?

<?php
$category_name = 'Categ开发者_JAVA技巧ory 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
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜