1

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.

1 Answer 1

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'));
2
  • 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?
    – Allen
    Commented Feb 29, 2012 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
    Commented Aug 23, 2012 at 6:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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