Risposte nei forum create
-
AutorePost
-
AleswarzPartecipante
Sicuro di aver messo quel codice? Io l’ho provato e funziona correttamente..comunque per l’altra domanda io farei sempre lo stesso procedimento lavorando però con l’offset, impostando l’offset decidi quali articoli escludere:
<?php $posts = get_posts( “numberposts=2&offset=1” ); ?>
<?php if( $posts ) : ?> <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
<h2><?php the_title(); ?></h2>
<?php the_category(‘, ‘) ?>
<?php endforeach; ?> <?php endif; ?> <!– con questo visualizzi gli ultimi 2 post (penultimo e terzultimo) -1 –>
<?php $posts = get_posts( “numberposts=2&offset=3” ); ?>
<?php if( $posts ) : ?> <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
<h2><?php the_title(); ?></h2>
<?php the_category(‘, ‘) ?>
<?php endforeach; ?> <?php endif; ?> <!– con questo visualizzi gli ultimi 2 post (quartulimo e quintultimo) -3 –>
Non so se ti è chiaro ma con il numero di offset escludi nel primo caso il primo articolo e nel secondo caso, essendo impostato a 3 il primo, penultimo e terz’ultimo
AleswarzPartecipanteBasta non specificare la categoria quando fai get_posts ovvero:
<?php $posts = get_posts( “numberposts=4&offset=1” ); ?>
AleswarzPartecipanteIo farei cosà¬: col primo ciclo chiami l’ultimo post della categoria “1” mentre col secondo chiami gli altri 4 sempre della categoria “1” mostrando solo titolo e categoria impostando però come offset “offset=1”. Impostando l’offset ad 1 il primo post non verrà mostrato mentre il 2,3,4,5 sà¬.
Spero di essere stato chiaro ed ovviamente se qualcuno conosce opzioni migliori e più sbrigative sarei felice di impararle!!
Ecco il codice:
<?php $posts = get_posts( “category=1&numberposts=1&offset=0” ); ?>
<?php if( $posts ) : ?> <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
<h2>” rel=”bookmark” title=”Permalink a <?php the_title(); ?>”><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php the_category(‘, ‘) ?>
<?php endforeach; ?> <?php endif; ?>
<?php $posts = get_posts( “category=1&numberposts=4&offset=1” ); ?>
<?php if( $posts ) : ?> <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
<h2>” rel=”bookmark” title=”Permalink a <?php the_title(); ?>”><?php the_title(); ?></h2>
<?php the_category(‘, ‘) ?>
<?php endforeach; ?> <?php endif; ?>
10 Maggio 2008 alle 14:22 in risposta a: come richiamare solo l’ultimo post di una categoria? #53538AleswarzPartecipanteIo per chiamare post di categorie diverse ad esempio in index.php uso questa funzione:
<?php $posts = get_posts( “category=1&numberposts=1” ); ?>
<?php if( $posts ) : ?> <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
<div class=”post_categoria_1″>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</div>
<?php endforeach; ?> <?php endif; ?>
<?php $posts = get_posts( “category=2&numberposts=1” ); ?>
<?php if( $posts ) : ?> <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
<div class=”post_categoria_2″>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</div>
<?php endforeach; ?> <?php endif; ?>
dove ovviamente con “category=1” chiami i post della categoria 1 e scegli quanti visualizzarne con “numberposts=1”.
AleswarzPartecipanteUna domanda interessante, mi accodo anche io alla richiesta
AleswarzPartecipanteCiao Iome, potresti spiegarmi come hai risolto il problema? Io mi trovo nella tua stessa situazione, vorrei lasciare per esempio due o tre righe per dividere i paragrafi dell’articolo, ma se premo invio più volte nell’editor li distacca ma pubblicando l’articolo scrive tutto ugualmente attaccato…
Ciao e grazie!
AleswarzPartecipanteSe fosse solo per me non ci sarebbero problemi a creare il link diretto alla pagina manualmente ma dato che ci dovranno scrivere anche altre persone avrei bisogno di trovare un modo per far avvenga in automatico il link all’articolo già postando la foto nell’editor.
-
AutorePost