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 have a homepage witch i am trying to query a custom post type as well as everything from the default posts,

right now i have 2 loops running everything looks good except i want the 2 different types to intermingle , if that makes sense.

Im running a jquery function that shows and hides posts from a either the custom post type or the default "Blog" post type. but since I have to loops the default posts always show up on top and the posts from the custom post type show up on the bottom, here is a link the my live page

http://themes.thefragilemachine.com/themachine_v4/

you can see that my custom post type is showing with a "w" icon, they are showing up near the end, but i want them to intermingle,. i know this is alot of type just trying to figure out the best way to explain what i would like too achieve. any help would be amazing! here is my code

            <?php if (have_posts()) : ?>
            <?php query_posts('posts_per_page=6');?>
            <?php while (have_posts()) : the_post(); ?>

            <div class="postitem mall floatleft myblog storm_fader">
            <div class="postitem-img lordfade">
            <a href="<?php the_permalink() ?>"><?php the_post_thumbnail('type2'); ?></a>
            </div>
            <div class="postitem-contentwrap">
            <div class="postitem-txt">
            <h6><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h6>
            <?php the_excerpt(''); ?>
            </div>
            <div class="postitem-info">
            <ul>
            <li><span class="post-label-blog"></span></li>
            <li class="spec"><a href="<?php the_permalink() ?>">
            <img src="/themachine_v4/wp-content/themes/themachine_v5_2/lib/imgs/img_gopost.jpg">
            </a></li>
            </ul>
            <div class="clear"></div>
            </div>
            </div>
            <div class="postitem-shadow"></div>
            </div>

            <?php endwhile; ?>
            <?php else : ?>
            <h2 class="center" style="color:#FFF;">ERROR</h2>
            <?php endif; ?>


            <?php rewind_posts(); ?>


            <?php if (have_posts()) : ?>
            <?php query_posts('post_type=work&posts_per_page=6');?>
            <?php while (have_posts()) : the_post(); ?>

            <div class="postitem mall floatleft mywork storm_fader">
            <div class="postitem-img lordfade">
            <a href="<?php the_permalink() ?>"><?php the_post_thumbnail('type2'); ?></a>
            </div>
            <div class="postitem-contentwrap">
            <div class="postitem-txt">
            <h6><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h6>
            <?php the_excerpt(''); ?>
            </div>
            <div class="postitem-info">
            <ul>
            <li><span class="post-label-work"></span></li>
            <li class="spec"><a href="<?php the_permalink() ?>">
            <img src="/themachine_v4/wp-content/themes/themachine_v5_2/lib/imgs/img_gopost.jpg">
            </a></li>
            </ul>
            <div class="clear"></div>
            </div>
            </div>
            <div class="postitem-shadow"></div>
            </div>

            <?php endwhile; ?>
            <?php else : ?>
            <h2 class="center" style="color:#FFF;">ERROR</h2>
            <?php endif; ?>
share|improve this question

1 Answer 1

up vote 1 down vote accepted

You are doing so many things wrong there, for example, you should only use query_posts once in a template file and on the main query of the page, anything else should be done using get_posts or WP_Query.

So to make you post types mingle you only need on query and you set the post type with an array:

<?php query_posts(array('posts_per_page' => 6, 'post_type' => array('work','post')));
if (have_posts()) : 
    while (have_posts()) : the_post(); ?>
        <div class="postitem mall floatleft myblog storm_fader">
        <div class="postitem-img lordfade">
        <a href="<?php the_permalink() ?>"><?php the_post_thumbnail('type2'); ?></a>
        </div>
        <div class="postitem-contentwrap">
        <div class="postitem-txt">
        <h6><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h6>
        <?php the_excerpt(''); ?>
        </div>
        <div class="postitem-info">
        <ul>
        <li><span class="<?php 
        if ($post->post_type =="post"){
            echo 'post-label-blog';
        }else{
            echo 'post-label-work';
        }?>"></span></li>
        <li class="spec"><a href="<?php the_permalink() ?>">
        <img src="/themachine_v4/wp-content/themes/themachine_v5_2/lib/imgs/img_gopost.jpg">
        </a></li>
        </ul>
        <div class="clear"></div>
        </div>
        </div>
        <div class="postitem-shadow"></div>
        </div>
    <?php endwhile; 
else : ?>
    <h2 class="center" style="color:#FFF;">ERROR</h2>
<?php endif; ?>
share|improve this answer
    
thanks for pointing that out, this is alot cleaner although im getting a Parse error: syntax error, unexpected ';' on line 16, –  The Fragile Machine Jun 21 '11 at 22:30
    
Yea sorry just updated the code, try now. –  Bainternet Jun 21 '11 at 23:28
    
Amazing that works! just had 1 more question, if you notice the code. there is a span class called "post-label-blog", i created one for work/portfolio as well that is called "post-label-work" is there a way tell WP to replace "post-label-blog" with "post-label-work" depending on if im posting to that post type or not? thank you so much for your help i will mark this answered, –  The Fragile Machine Jun 24 '11 at 18:32
    
@The Fragile Machine : Yes you can ,you check the post type, i just updated my answer so try the new code. –  Bainternet Jun 24 '11 at 23:29
    
That worked great! thank you so much! this is worth more than gold to me! :) –  The Fragile Machine Jun 25 '11 at 17:06

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.