Home › Forum › Problemi Vari con WP › Alle prime armi con l’uso dei cicli WP
-
AutorePost
-
-
31 Maggio 2008 alle 6:34 #6816buddhapax2008Partecipante
Salve,
uso WP 2.5.1.
Dovendo strutturare una home page diversa dal blog, mi trovo ad usare i cicli per visualizzare gli utlimi post di certe categorie sulla mia pagina principale.
Uso il seguente codice:
<td>
<?php while (have_posts()) : the_post(); ?>
<?php $posts = get_posts( "category=3&numberposts=1" ); ?> <?php if( $posts ) : ?>
<?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
<?php if (yapb_is_photoblog_post()): ?>
<?php yapb_image('', array('alt' => 'Prova'), '') ?>
<?php else: ?>
<?php endif ?>
<?php endforeach; ?> <?php endif; ?>
<?php endwhile; ?></td>
<td style="padding-left: 5px; vertical-align:top;">
<div style="text-align:justify;"><?php while (have_posts()) : the_post(); ?>
<?php $posts = get_posts( "category=3&numberposts=1" ); ?> <?php if( $posts ) : ?> <?php foreach( $posts as $post ) : setup_postdata( $post ); ?> <h2>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></h2> <?php the_content("Continua '" . the_title('', '', false) . "'"); ?> <?php endforeach; ?> <?php endif; ?>
<?php endwhile; ?></div></td>
dimodoché in una cella si possa vedere l'immagine associata al post con il plug-in YAPB, mentre in quella adiacente si posse leggere un riassunto.
Adesso il problema è che questo articolo con immagine viene ripetuto per un numero di volte uguale al numero dei miei post in totale.
Ciò sicuramente dipende da
<?php while (have_posts()) : the_post(); ?>
.
Adesso vi chiedeo è giusto utilizzare un ciclo solo per un post? E se no avreste del codice da consigliarmi?
Vi ringrazio.
D.
-
31 Maggio 2008 alle 12:08 #54173ArturoPartecipante
il loop di wp parte con
<?php while (have_posts()) : the_post(); ?>
tu lo richiami due volte, apri il loop, ci metti la parte di codice di YAPB per far uscire l’immagine, ci metti il codice di WP per far uscire il testo e tutto quello che ne consegue, chiudi il loop.
ora come YAPB richiami l’immagine non lo so’ di preciso, ma dovrebbe essere cosi’, per far uscire un solo articolo devi impostarlo nel backend di wp, e comunque una volta impostato il loop in modo corretto, al massimo visualizzerai il numero di post massimi per pagina ma tutti diversi non solo lo stesso ripetuto n volte.
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.