views:

109

answers:

1

I'm using this codes for category.php template on my new work (photos page).

But there are problem on category bar. When i click on any category link then all post is showing under first category item. I can't categorize my posts.

How i can solve this problem?

+1  A: 

I solved this problem with getting current category id and using it like this:

<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
foreach((get_the_category()) as $category) { $postcat= $category->cat_ID; }
$wp_query->query('cat=' . $postcat . '&paged=' . $paged);
?>

<?php while ($wp_query->have_posts()): $wp_query->the_post();?>

<?php 
$img_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts where post_parent= $post->ID and (post_mime_type = 'image/jpeg' OR post_mime_type = 'image/gif' OR post_mime_type = 'image/png') and post_type = 'attachment'");
$img_array = wp_get_attachment_image_src($img_id, 'thumbnail', false);
$img_array_l = wp_get_attachment_image_src($img_id, 'large', false);    
?>
<li><a href="<?php echo $img_array_l[0]; ?>" rel="photos"><?php echo '<img src="'.$img_array[0].'"' . ' alt="'.get_the_title().'" />'; ?></a></li>

<?php endwhile;?>
fatihturan