Home › Forum › Problemi Vari con WP › Pubblicare Articoli SOTTO una Pagina
-
AutorePost
-
-
9 Marzo 2012 alle 11:46 #21028Winter_SoldierPartecipante
Salve a tutti,
Mi chiedevo se ci fosse la possibilità di pubblicare una categoria di articoli SOTTO il contenuto di una pagina.
In pratica ho una slide di immagini e di sotto vorrei mostrare gli articoli pubblicati nella categoria “News”.
àˆ possibile qualcosa del genere? Ho provato a modificare il loop ma mi sostituisce la pagina intera con gli articoli.
Grazie anticipatamente.
-
9 Marzo 2012 alle 14:57 #94248Alt Design Web AgencyPartecipante
1) Crea un template apposito per quella pagina oppure copia il file page.php e rinomina il nuovo file in page-SLUGDELLATUAPAGINA.php
2) Inserisci il seguente codice nella zona che ti interessa. Dopo la chiamata a the_content() dovrebbe andare bene. Questo crea una lista degli articoli (titolo cliccabile).
<h3>News</h3>
<?php $my_query = new WP_Query(array(‘category_name’=>’news’,’showposts’=>5)); ?>
<?php if ($my_query->have_posts()){ ?>
-
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
- ‘ title='<?php the_title_attribute(); ?>’><?php the_title(); ?>
<?php endwhile; ?>
<?php } ?>
3) Modifica l’attributo category_name con lo slug della tua categoria (qui ho ipotizzato “news”), mentre showpost indica quanti articoli vengono visualizzati.
4) Se vuoi aggiungere anche il testo del riassunto o l’intero articolo devi chiamare anche the_excerpt o the_content e modificare leggermente l’html
Ciao!
-
9 Marzo 2012 alle 15:01 #94249Alt Design Web AgencyPartecipante
Non inserisce correttamente il codice HTML, la parte corretta di codice (in arancione) qui sopra è questa:
< li >< a >” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></ a ></ li >
togliete gli spazi nei tag: a, li
-
9 Marzo 2012 alle 23:32 #94262Winter_SoldierPartecipante
In questa maniera purtroppo mi visualizza solo un elenco con i titoli! Come posso avere l’articolo vero e proprio?
-
10 Marzo 2012 alle 12:31 #94266Alt Design Web AgencyPartecipante
4) Se vuoi aggiungere anche il testo del riassunto o l’intero articolo devi chiamare anche the_excerpt o the_content e modificare leggermente l’html
Al posto di
< li >< a >” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></ a ></ li >
scrivi
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.