Tuesday, 20 August 2013

Wordpress get cat id - >change class

Wordpress get cat id - >change class

I am trying to find an solution for this.
I want to change the class of the post with php in the loop.
So i get the cat ID of the post and make an if function for the
corresponding id, where the class should be changed accordingly.
But somehow he only gets the id one time and prints the same for every post.
Somebody know why?
<?php query_posts('cat=23,29,30,31'.'&showposts=50'.'&orderby=rand'); if
(have_posts()) : while (have_posts()) : the_post(); ?>
<?php $cat = get_cat_ID( single_cat_title("",false) );
print_r($cat);
if ( $cat= "23" ) {
$size="poststart";
}
else if ( $cat= "29" ) {
$size="postcp2";
}
else if ( in_array("30", $category_id) ) {
$size="postcp3";
}
else if ( in_array("31", $category_id) ) {
$size="postfast";
}
unset ($cat);
print_r($cat);
?>
<div class="<?php echo $size ?>" id="post-<?php the_ID(); ?>">

No comments:

Post a Comment