Come mostrare tutti i post della categoria in wordpress?
-
-
Poichénon sono uno sviluppatore,ci hoprovatoe ora utilizzo "Visualizzazioni contenuto".Puoi usarloper visualizzare soloi post delle categorie.Ottimoplugin!Because I'm not a developer, I've tried and I'm now using "Content Views". You can use it to display category posts only. Great plugin!
-
4 risposta
- voti
-
- 2011-05-18
<?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; ?>
cambia semplicemente l'ID della categoria (numero 7) e cambiailpost_type cheeranelplugin
per ulterioriinformazioni supost_type,vedereil collegamento http://codex.wordpress.org/Custom_Post_Types
<?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; ?>
just change the category id (number 7) and change the post_type that was in the plugin
to learn more about post_type, see link http://codex.wordpress.org/Custom_Post_Types
-
- 2011-05-17
È abbastanzafacilefarlo con wordpress.Devi capire chei post vengononormalmente visualizzati all'interno di un "loop",unpiccolo codice che si ripete.Devi usarne unoperfarlo.
<?php $catPost = get_posts(get_cat_ID("NameOfTheCategory")); //change this 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;?>
Dovrestimodificare l'outputin base alletueesigenze
It is quite easy to do it with wordpress. You have to understand that post are normally display within a "loop", a small code that repeat itself. You have to use one to do that.
<?php $catPost = get_posts(get_cat_ID("NameOfTheCategory")); //change this 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;?>
You should change the output to what fit your needs
-
- 2018-09-21
Puoi utilizzare questo codiceper accedere atuttii post di una categoria specifica.Nellatuapagina category.php usa la spinetta del codice
$current_category = get_queried_object(); ////getting current category $args = array( 'post_type' => 'our-services',// your post type, 'orderby' => 'post_date', 'order' => 'DESC', 'cat' => $current_category->cat_ID // current category ID ); $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;
You can use this code for accessing all post of specific category. In your category.php page use the spinet of code
$current_category = get_queried_object(); ////getting current category $args = array( 'post_type' => 'our-services',// your post type, 'orderby' => 'post_date', 'order' => 'DESC', 'cat' => $current_category->cat_ID // current category ID ); $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;
-
- 2016-01-26
Questo è adattato dal codice scritto da qualcun altroe di cui hobeneficiatotroppotempofaper sapere da doveprovenisse (se lapersona che lo ha scritto originariamente sta leggendo questo,grazie ancora).Funzionaper latua 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="Permanent Link to <?php the_title_attribute(); ?>"> <?php the_post_thumbnail('name of your thumbnail'); ?> </a> <h4> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <?php the_title(); ?> </a> </h4> <hr/ style="clear:both;"> <?php endforeach;?>
This is adapted from code someone else wrote, and which I benefitted from too long ago to know where it came from (if the person who originally wrote it is reading this, thanks again). It works for your request:
<?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="Permanent Link to <?php the_title_attribute(); ?>"> <?php the_post_thumbnail('name of your thumbnail'); ?> </a> <h4> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <?php the_title(); ?> </a> </h4> <hr/ style="clear:both;"> <?php endforeach;?>
Ho creato una categoria utilizzandoilplug-in Custom Post Typee ora vengono visualizzati soloi 5postpiù recenti della categoria.
Quello che voglio èmostraretuttii postper la categoria.
Adesempio,supponiamo cheio abbia una categoria difilm: vogliotuttii filmin quella categoria.
Quale codice devo usaree dove?
Non somolto di wordpress,quindi apprezzerei unprocessograduale.