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'm trying to get the hang of custom post types and I am trying to get them to loop through the post types within a page template. I'm already using the MultiEdit plugin to display certain content regions within my template. Overall, here is what my template page looks like:

<?php
/*
Template Name: Home Template
MultiEdit:Icons,NameTitle,CategoriesTitle
*/
?>
<?php get_header(); ?>
<?php query_posts( 'post_type=homecategories'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<div class="main">

<section>


<div class="icons">
<?php multieditDisplay('Icons'); ?>
</div><!--end icons-->

<div class="slider">

    <?php the_content(); ?>

    </div><!--end slider-->

    <div class="title">
    <?php multieditDisplay('NameTitle'); ?>
    </div>

<div class="categories">

    <?php multieditDisplay('CategoriesTitle'); ?>


    <!--this is where I want the custom posts to loop through-->

    <div class="items">


    <!--image of the custom post type-->
    <img src="" />

    <span><!--title of custom post type--></span>

    </div>
    <!--end of the custom posts loop-->


</div><!--end categoires-->

    <div class="news">

    </div><!--end news-->


        <?php edit_post_link('Edit this entry.', '<p>',      '</p>');     
?>      
</section>
</div><!--end main-->       
    <?php //comments_template(); ?>
    <?php endwhile; endif; ?>
<?php //get_sidebar(); ?>
<?php get_footer(); ?>

If I keep it like this the only thing that shows is the entries from the custome post type and nothing else. And what I am trying to accomplish is get it to only display the custom post types within this section in the template:

 <div class="items">


<!--image of the custom post type-->
<img src="" />

<span><!--title of custom post type--></span>

</div>
<!--end of the custom posts loop-->

Like I mentioned, I'm still getting the hang of using and implementing custom post types and I'm not really sure if this is the right way to go or not.

Thanks!

share|improve this question
1  
What's the problem? Does this code display your posts? And what is the name of your custom post type? Your code suggests it's homecategories, which sounds like a name for a taxonomy, not post type. –  dalbaeb Mar 21 '13 at 18:28
    
@dalbaeb If I keep it like this, it removes all the other content areas an only displays the custom post types. What I want it to do is only display within a certain section of my template and not the whole thing and I'm not sure how that all works with custom post types. Like to I need to create a separate file that pulls the custom post types and then use like a PHP include within my template code (seen above) or maybe a shortcode? Like I mentioned, using custom post types is very new to me. –  ultraloveninja Mar 21 '13 at 18:42
    
@dalbaeb I updated my post for a little more clarity. –  ultraloveninja Mar 21 '13 at 18:44
add comment

1 Answer

up vote 0 down vote accepted

Looping through posts

First of all, you need to have two separate loops - one for whatever it is that it's displaying right now and second one for your custom post type. Right now the block where you want your custom posts to appear is located within the first loop, and that's not good. I suggest that you read up on The Loop, and especially check some examples of multiple loops.

By the way, one can have nested loops, but that's most likely not your case.

Templates

Also, from your comment not sure if that's what you need, but for templating you can always take advantage of WordPress template hierarchy. That way you can have a separate template file for each of your custom post types, and then you fully control how each custom post appears.

For listing posts you need to look at the Custom Post Types display section.

share|improve this answer
    
Thanks for the info and the help! I really appreciate it. I think I found a solution. I created a separate PHP file to loop through my custom post type. And then I did a php include to the PHP file that has the custom post loop. Now, I am not sure if this is the absolute best way to do this, but in some zany way...it works. –  ultraloveninja Mar 21 '13 at 19:11
add comment

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.