web-dev-qa-db-fra.com

Problèmes d'exclusion d'un post-type personnalisé de la boucle

Bonjour à tous,

J'ai des problèmes pour exclure mes événements post-type personnalisés de ma boucle index.php pour ma page Blog.

Je souhaite simplement afficher les publications de mon blog actuel, qui, je suppose, relève du type de publication "post", mais lorsque j'essaie d'afficher le type "publication", il affiche également le type de publication "événements".

Voici mon code de boucle:

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

J'ai aussi essayé cela, sans succès:

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

Merci

2
remi90

Essayez d’utiliser ce qui suit avant "if (have posts().."

$args = array(
    'post_type' => 'post',
    'orderby'   => 'Rand',
    'showposts' => '1'
);
query_posts( $args );
1
Henry

Pas besoin d'exclure le 'events' vous venez d'extraire le type 'post'.

Voir l'exemple -

$args = array( 'post_type' => 'post', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
    the_title();
    echo '<div class="entry-content">';
    the_content();
    echo '</div>';
endwhile;

il va chercher de'post_type' => 'post', et le nombre de page = 10.

Pour plus de détails, s\vérifiez le lien, vous aurez une idée de l’URL: http://codex.wordpress.org/Post_Types

4
w3uiguru