Aller au contenu

limiter une boucle à un site


prem

Sujets conseillés

Hello j'aurais besoin urgemment de votre aide svp... Cela fais des jours que je bloques.
Voilà j'ai des posts , chaque posts a plusieurs categories.

j'ai fais une requete wp_query pour lister tous les posts sauf une categorie ,mais je me retrouves avec des doublons . voila mon code 

<?php
/**
 * The template for displaying a grid item.
 *
 * @package WordPress
 * @subpackage Edition
 * @since Edition 1.0
 */


$do_not_duplicate = array(); 
$query = new WP_Query( array( 'category__not_in' => array( 32 ) ) );

 if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
 $do_not_duplicate[] = $post->ID; 

global
$tw_section, // section object
$grid_size, // grid size
$post;       // section object

$section_id    = get_the_ID($post);  // section id
$tw_categories = get_categories();   // get all post categories
$post_type     = get_post_type();


$thumbnail_size = 'half';
$thumbnail_size = ($grid_size == 'fullgrid') ? 'big' : $thumbnail_size;
if ($grid_size == 'related') {
    $thumbnail_size = 'related';
} ?>

<div class="<?php if ( isset($tw_categories[0]->term_id) ) { echo 'highlight_category_' . $tw_categories[0]->term_id; } ?> <?php echo (has_post_thumbnail()) ? 'has-thumbnail' : 'no-thumbnail'; ?> <?php echo $grid_size;?> grid-item">
    <div class="isobrick-inner">
        <?php
            the_post_thumbnail($thumbnail_size, array(
                'onload' => 'jQuery(this).animate({ "opacity" : 0.75 }, 500);'
            ));
        ?>

        <?php echo themewich_review_circle('none', false); ?>

        <?php if ( 'post' == $post_type ) : ?>
            <span class="thumboverdate">
                <i class="fa fa-bookmark"></i>
                <?php themewich_date('human'); ?>
            </span>
        <?php else: ?>
            <?php if ( function_exists( 'wc_get_template' ) ) : ?>
                <span class="thumboverdate">
                    <?php wc_get_template( 'loop/price.php' ); ?>
                </span>
            <?php endif; ?>
        <?php endif; ?>

        <div class="thumbovertext">
            <div class="badge">
                <?php echo ag_get_cats(3); ?>
            </div>
            <h2 class="title">
                <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                    <?php
                        $title = get_the_title();
                        if (strlen($title) >= 75) {
                             $title = mb_substr($title, 0, 75) . "... ";
                        }
                        echo $title;
                    ?>
                </a>
            </h2>

            <?php if ( 'post' == $post_type ) : ?>
                <?php preg_match('/<!--more(.*?)?-->/', $post->post_content, $matches); ?>
                <a class="button outline" href="<?php the_permalink(); ?>"  title="<?php the_title_attribute(); ?>">
                    
                    <?php
                        if ( isset($matches[1]) && $matches[1] ) {
                            echo $matches[1];
                        } else {
                            _e('Lire la suite', 'themewich');
                        }
                    ?>
                </a>
            <?php endif; ?>

        </div>

        <a class="brick-thumb-link" href="<?php the_permalink(); ?>"  title="<?php the_title_attribute(); ?>">
            <?php the_title(); ?>
        </a>
    </div>
</div>



<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>

 

 

 

et quand je fais un var_dump ($do_not_duplicate);

j'obtiens 

array(1) { [0]=> int(470) }

array(2) { [0]=> int(470) [1]=> int(368) } 

array(3) { [0]=> int(470) [1]=> int(368) [2]=> 

 

 

et je souhaiterai avec l'aide d'un foreach ne poster mon article qu'une fois

Lien vers le commentaire
Partager sur d’autres sites

Veuillez vous connecter pour commenter

Vous pourrez laisser un commentaire après vous êtes connecté.



Connectez-vous maintenant
×
×
  • Créer...