Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using this code to show posts in columns. How can I set this part ('cat=3&numberposts=5&offset=0') as so archive page should automatically get posts from clicked catagory?

<div id="column1">

<?php $posts = get_posts('cat=3&numberposts=5&offset=0'); foreach ($posts as $post) : start_wp(); ?>
<?php static $count1 = 0; if ($count1 == "5") { break; } else { ?>

<a href="<?php the_permalink() ?>" rel="<?php _e("bookmark", "solostream"); ?>" title="<?php _e("Permanent Link to", "solostream"); ?> <?php the_title(); ?>"><?php the_post_thumbnail( 'homepage-thumb' ); ?></a>
<br><strong><?php the_title(); ?><strong><br>
<?php the_field('price'); ?>
<div style="clear:both;"></div>
<?php $count2++; } ?>
<?php endforeach; ?>

</div>

    <div id="column2">

<?php $posts = get_posts('cat=3&numberposts=5&offset=5'); foreach ($posts as $post) : start_wp(); ?>
<?php static $count2 = 0; if ($count2 == "5") { break; } else { ?>

<a href="<?php the_permalink() ?>" rel="<?php _e("bookmark", "solostream"); ?>" title="<?php _e("Permanent Link to", "solostream"); ?> <?php the_title(); ?>"><?php the_post_thumbnail( 'homepage-thumb' ); ?></a>
<br><strong><?php the_title(); ?><strong><br>
<?php the_field('price'); ?>
<div style="clear:both;"></div>
<?php $count2++; } ?>
<?php endforeach; ?>
    </div>
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Instead of using the number 3, you get the current category by doing the following:

$cat_ID = get_query_var('cat');
$posts = get_posts('cat='.$cat_ID.'&numberposts=5&offset=0');
share|improve this answer
    
fine it worked Tom :) –  Ahmad Nov 17 '11 at 5:57
    
can you accept this answer? ( the green tick underneath the arrows ) –  Tom J Nowell Nov 17 '11 at 10:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.