Morning all,
I’m having some issues with excluding my custom post-type ‘events’ from my index.php loop for my Blog page.
I simply want to display the posts from my actual Blog, which I assume come under the post-type ‘post’, but when I try to display the ‘post’ type it also shows my ‘events’ post-type.
Here’s my loop code:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="individualPost">
<h1 class="bottomBorder"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
<ul class="blogMeta">
<li><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></li>
<li>Posted in <?php the_category(', '); ?></li>
</ul>
<?php if (has_post_thumbnail( $post->ID )): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/thumbs.php?src=<?php echo $image[0]; ?>&w=615&h=200&zc=1" alt="<?php the_title(); ?>" /></a>
<?php endif; ?>
<!-- Display the Post's Content in a div box. -->
<?php the_excerpt(); ?>
</div>
<?php endwhile;?>
<?php else : ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1>Not Found</h1>
</div>
<?php endif; ?>
I’ve also tried this, with no luck:
<?php $loop = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 5 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="individualPost">
<h1 class="bottomBorder"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
<ul class="blogMeta">
<li><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></li>
<li>Posted in <?php the_category(', '); ?></li>
</ul>
<?php if (has_post_thumbnail( $post->ID )): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/thumbs.php?src=<?php echo $image[0]; ?>&w=615&h=200&zc=1" alt="<?php the_title(); ?>" /></a>
<?php endif; ?>
<!-- Display the Post's Content in a div box. -->
<?php the_excerpt(); ?>
</div>
<?php endwhile;?>
Thanks
Try using the following before “
if (have posts()..
“No need to exclude the
'events'
you just fetch the ‘post’ type.See the example –
it will fetch from
'post_type' => 'post'
, and number ofpage = 10
.For more details scheck the link you will get some idea
url: http://codex.wordpress.org/Post_Types
Had the same issue, it can be probably related to the fact that you use a statc page as the homepage, and a “blog” page for the post stream.
I solved putting this code before the loop:
This works for me, but in order to correctly display your ‘events’ you need to create a archive-events.php with a plain loop without the query_post function.
I have a “standard loop” in a loop.php that i call with
And I use the query_posts in the templates.
i.e my inex.php presents
but my archive-mycustomposttype.php has only
Cheers