Skip to content

Instantly share code, notes, and snippets.

@pixelbart
Last active April 19, 2016 14:15
Show Gist options
  • Save pixelbart/466446848eb45c919c67417a106ba5db to your computer and use it in GitHub Desktop.
Save pixelbart/466446848eb45c919c67417a106ba5db to your computer and use it in GitHub Desktop.
Custom WP-Query
<?php
// https://codex.wordpress.org/Class_Reference/WP_Query
$args = array(
'category_name' => 'KATEGORIE1, KATEGORIE2', // Hier können einzelne Kategorie gewählt werden
'post_type' => 'post', // Hier wird angegeben, was angezeigt werden soll. (Post ist Standard; Geht auch Custom Post Type)
);
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<!-- AB HIER STARTET DER EINZELNE BEITRAG -->
<h2><?php the_title() ;?></h2>
<?php the_post_thumbnail(); ?>
<?php the_excerpt(); ?>
<!-- HIER ENDET DER EINZELNE BEITRAG -->
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<!-- DAS WIRD AUSGEBEN, WENN KEINE BEITRÄGE VORHANDEN SIND -->
<p><?php _e( 'Keine Beiträge gefunden.', 'casacara' ); ?></p>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment