Domanda

Come riscrivo il if (have_posts()) : ... while (have_posts()) : the_post(); Stile WordPress Loop di seguito come uno stile di stile New_Query usando <?php $the_query = new WP_Query();? ( Come mostrato in http://codex.wordpress.org/class_reference/wp_query )

Il ciclo corrente di seguito alterna le classi post per visualizzare una griglia di post larghe due post (vedere l'immagine sotto). Ma ho bisogno di riscriverlo usando una nuova query in modo che io possa: 1) Aggiungi un conteggio dei post e 2) un conteggio post offset su di esso. Il motivo è che devo usarlo nel modello di pagina con un altro ciclo basato su una nuova query.

Questo ciclo alterna la classe tra "post irregolare" e "post" per visualizzare i post (vedere nell'immagine qui sotto.) Devo conservare quella funzione in un nuovo ciclo WP_Query.

<?php

    if (have_posts()) :
    $odd = false;
    while (have_posts()) : the_post();
    $odd = !$odd;
    ?>

    <div class="<?php if ($odd) echo 'uneven '; ?>post">

    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>

    <?php the_excerpt(); ?> 

    </div>

    <?php endwhile; else: endif; ?>

Il loop sopra mostra post come questo:

enter image description here

Questo è un nuovo ciclo WP_Query standard:

<?php $my_query = new WP_Query('offset=5&showposts=10'); ?>

<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>

<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">

<?php the_title(); ?></a>

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange
scroll top