Articoli di sottocategorie
-
-
Prova a scrivere questo codice, se non funziona prova a modificarlo. Non l'ho proprio testato e penso che sicuramente c'è qualche errore, in ogni caso penso tu debba fare una cosa del genere:
<?php
$sub_args = array(
'child_of' => /* Qui va l'ID della categoria A */ ,);$subcategories = get_categories( $sub_args );
for($i=0;isset($subcategories[$i]);$i++) {
$post_args = array(
'posts_per_page' => 1,
'category_name' => $subcategories[$i]->name,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish', );$posts_array = get_posts( $post_args );
foreach ($posts_array as $single_post) {
setup_postdata($single_post); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt();
}
}
?> -
-
-
Prova a riscrivere il foreach in questo modo:
foreach ($posts_array as $single_post) {
setup_postdata($single_post); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt();
wp_reset_postdata(); /* Aggiunta */
} -
-
-
Ok allora ti dico che se tu scrivessi in questo modo, ti farebbe visualizzare i titoli giusti di ogni articolo:
foreach ($posts_array as $single_post) {
setup_postdata($single_post); ?>
<h2><a href="<?php echo get_permalink($single_post->ID); ?>"><?php echo get_the_title($single_post->ID); ?></a></h2>
<?php the_excerpt();
wp_reset_postdata();
}Il fatto è che non riesco a trovare un modo per recuperare il contenuto di un post tramite ID. Vedi se tu ci riesci.
-
Anzi prova così:
foreach ($posts_array as $single_post) {
setup_postdata($single_post); ?>
<h2><a href="<?php echo get_permalink($single_post->ID); ?>"><?php echo get_the_title($single_post->ID); ?></a></h2>
<?php echo get_post($single_post->ID)->post_excerpt;
wp_reset_postdata();
} -
Ciao. Scusami per il ritardo ma per un paio di giorni non sono riuscito a lavorarci.
Perfetto, funziona. Veramente molte grazie.
Questo il nuovo codice, per le persone a cui potrebbe servire. Ciao
<?php
$sub_args = array(
'child_of' => /* ID Categoria */ ,);$subcategories = get_categories( $sub_args );
for($i=0;isset($subcategories[$i]);$i++) {
$post_args = array(
'posts_per_page' => 1,
'category_name' => $subcategories[$i]->name,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish', );$posts_array = get_posts( $post_args ); foreach ($posts_array as $single_post) { setup_postdata($single_post); ?>
<h2><a href="<?php echo get_permalink($single_post->ID); ?>"><?php echo get_the_title($single_post->ID); ?></a></h2>
<?php the_excerpt(); wp_reset_postdata(); } }?>
-
Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.
Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.
Con il tuo contributo, questo post potrebbe essere ancora migliore 💗
Registrati Accedi
Grazie veramente molto