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 get custom posts in rows.

<?php query_posts('posts_per_page=72&cat=' . $cat . '&order=ASC');
$columns = 5;
$increment = 0;
?>
<table class="cat">
    <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
        <?php if($increment % $columns == 0){ // if increment is divisable by columns (ie 3/3 = 0))?>
        <tr>
            <td>
                <div class="post" id="<?php the_ID(); ?>">
                <div class="entry"><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>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                </div>

                </div> <!-- .post -->
            </td>

        <?php
        }else{
        ?>
            <td>
                <div class="post" id="<?php the_ID(); ?>">
                <div class="entry"><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>
                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                </div>

                </div> <!-- .post -->
            </td>               

    <?php }$increment++; endwhile; endif;?>
</tr></table>

Problem is that it does not give custom posts. I want to use it on category page. How to amend first section so it automatically grabs posts from current category of either posts or custom post type.

share|improve this question

1 Answer 1

Using query_posts() you can pass 'post_type=custom-post-type' it will however not work with a category associated with default posts but instead you can pass the custom taxonomy name are the value taxonomy=taxonomy_value

You'll need to do something like:

query_posts(array('post_type' => 'customposttype', 'posts_per_page' => 72,
'custom_taxonomy_name' => 'custom_taxonomy_value', 'order' => 'ASC'));
share|improve this answer
    
Then how to alter first section of code <?php query_posts('posts_per_page=72&cat=' . $cat . '&order=ASC'); $columns = 5; $increment = 0; ?> to give required result? –  Ahmad Feb 29 '12 at 20:59
    
post_type can also take an array, so you could make it show both post and customposttype, though it is bound to get messy with the taxonomy... –  Jake Aug 23 '12 at 6:16

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.