In diesem Artikel:
Kategorie: Wordpress Wordpress: get_the_category_list , get_the_date , the_permalink , the_title , wp_query , wp_reset_postdataZur Anzeige der aktuellsten Beiträge auf einer Seite wird der folgenden Code in eine Seiten-Template-PHP eingefügt.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | <div id= "Start_Beitraege" > <h2>Letzte Beiträge</h2> <ul> <?php // the query $args = array ( 'post_type' => 'post' , 'showposts' => '12' , 'post_status' => 'publish' ); $the_query = new WP_Query( $args ); ?> <?php if ( $the_query ->have_posts() ) : ?> <!-- pagination here --> <!-- the loop --> <?php while ( $the_query ->have_posts() ) : $the_query ->the_post(); ?> <li> <a href= "<?php echo the_permalink( $post->ID ); ?>" > <?php the_title(); ?> </a> <div id= "Start_Beitraege_Meta" > Kategorie: <?php echo get_the_category_list( __( ', ' , 'twentysixteen' ) ); ?> Datum: <?php echo get_the_date(); ?> </div> </li> <?php endwhile ; ?> <!-- end of the loop --> <!-- pagination here --> <?php wp_reset_postdata(); ?> <?php else : ?> <p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p> <?php endif ; ?> </ul> </div><!-- Ende: Start_Beitraege --> |
Das Beispiel generiert eine Liste der letzten 12 Beiträge, die den Status publish haben.
Des Weiteren werden die Kategorien (get_the_category_list) und das Beitragsdatum (get_the_date) ausgegeben.
Der Titel wird als html-Verweis auf the_permalink dargestellt.
1 | <a href= "<?php echo <strong>the_permalink</strong>( $post->ID ); ?>" > <?php <strong>the_title</strong>(); ?> </a> |
Im WordPress Codex werden alle verfügbaren Parameter beschrieben.
https://codex.wordpress.org/Class_Reference/WP_Query
Selektionen (und Sortierungen) sind möglich nach:
- Author
- Category
1 | 'cat' => '1,2,3,4' |
- Tag
- Taxonomy
- Search Keywords
- Post and Page Parameters
- Password Parameters
- Post Type
1 | 'post_type' => array ( 'post' , 'page' , '<em>my_post_type</em>' ) |
- Status
1 | 'post_status' => array ( 'pending' , 'draft' , 'future' , 'publish' ) |
- Comments
- Pagination
- Order und Orderby
- Date
- Custom Fields
- Permissions