Come mostrare tutti i post di una categoria in WordPress?

17 mag 2011, 14:37:09
Visualizzazioni: 115K
Voti: 11

Ho creato una categoria utilizzando il plugin Custom Post Type, e al momento vengono mostrati solo i 5 post più recenti della categoria.
Quello che vorrei è mostrare tutti i post della categoria.
Per esempio, supponiamo di avere una categoria film - voglio vedere tutti i film in quella categoria.
Quale codice dovrei usare e dove?
Non ho molta esperienza con WordPress, quindi apprezzerei una spiegazione passo per passo.

1
Commenti

Poiché non sono uno sviluppatore, ho provato e ora sto utilizzando "Content Views". Puoi usarlo per visualizzare solo i post di categoria. Ottimo plugin!

User User
1 apr 2016 02:15:22
Tutte le risposte alla domanda 4
0
14
   <?php
    $args = array( 'category' => 7, 'post_type' =>  'post' ); 
    $postslist = get_posts( $args );    
    foreach ($postslist as $post) :  setup_postdata($post); 
    ?>  
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
    <?php the_excerpt(); ?>  
    <?php endforeach; ?> 

modifica solo l'ID della categoria (il numero 7) e cambia il post_type che era nel plugin

per saperne di più su post_type, consulta il link http://codex.wordpress.org/Custom_Post_Types

18 mag 2011 09:04:11
0

È abbastanza semplice farlo con WordPress. Devi capire che i post vengono normalmente visualizzati all'interno di un "loop", un piccolo codice che si ripete. Devi usarne uno per ottenere questo risultato.

<?php 
 $catPost = get_posts(get_cat_ID("NomeDellaCategoria")); //modifica questo
   foreach ($catPost as $post) : setup_postdata($post); ?>
       <div>
             <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
             <p><?php the_content(); ?></p>
       </div>
<?php  endforeach;?>

Dovresti modificare l'output in base alle tue esigenze

17 mag 2011 15:15:59
0

Puoi utilizzare questo codice per accedere a tutti i post di una categoria specifica. Nella tua pagina category.php usa lo snippet di codice

$current_category = get_queried_object(); ////ottiene la categoria corrente
$args = array(
        'post_type' => 'our-services',// tuo post type,
        'orderby' => 'post_date',
        'order' => 'DESC',
        'cat' => $current_category->cat_ID // ID della categoria corrente
);
$the_query = new WP_Query($args);
if($the_query->have_posts()):
   while($the_query->have_posts()): $the_query->the_post();
    echo "<h2>".the_title()."</h2>";
    echo "<p>".the_content()."</p>";
endwhile;
endif;
21 set 2018 03:16:04
0

Questo codice è un adattamento di qualcosa scritto da qualcun altro, e che ho beneficiato tanto tempo fa da non ricordare più la fonte (se la persona che lo ha scritto originariamente sta leggendo, grazie ancora). Funziona per la tua richiesta:

<?php
$catPost = get_posts('cat=888&posts_per_page=-1000');
   foreach ($catPost as $post) : setup_postdata($post); ?>
  <a href="<?php the_permalink() ?>" rel="bookmark" title="Link Permanente a <?php the_title_attribute(); ?>">
    <?php the_post_thumbnail('nome del tuo thumbnail'); ?>
  </a>

<h4>
  <a href="<?php the_permalink() ?>" rel="bookmark" title="Link Permanente a <?php the_title_attribute(); ?>">
    <?php the_title(); ?>
  </a>
</h4>
<hr/ style="clear:both;">
<?php  endforeach;?>
27 gen 2016 01:15:01