0

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; ?>

1 Answer 1

1

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; ?>
5
  • thanks for pointing that out, this is alot cleaner although im getting a Parse error: syntax error, unexpected ';' on line 16, Commented Jun 21, 2011 at 22:30
  • Yea sorry just updated the code, try now.
    – Bainternet
    Commented Jun 21, 2011 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, Commented Jun 24, 2011 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
    Commented Jun 24, 2011 at 23:29
  • That worked great! thank you so much! this is worth more than gold to me! :) Commented Jun 25, 2011 at 17:06

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.