WordPress Loop
Standard Loop
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
// Content here
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php the_post_thumbnail(); ?>
<?php the_content(); ?>
<?php endwhile; else: ?>
<?php _e( 'Tut mir leid, keine Einträge vorhanden.'); ?>
<?php endif; ?>
Erweiterter Loop
<!-- Start the Loop. -->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!-- Test if the current post is in category 3. -->
<!-- If it is, the div box is given the CSS class "post-cat-three". -->
<!-- Otherwise, the div box is given the CSS class "post". -->
<?php if ( in_category( '3' ) ) : ?>
<div class="post-cat-three">
<?php else : ?>
<div class="post">
<?php endif; ?>
<!-- Display the Title as a link to the Post's permalink. -->
<h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
<small><?php the_time('F jS, Y'); ?> by <?php the_author_posts_link(); ?></small>
<!-- Display the Post's content in a div box. -->
<div class="entry">
<?php the_content(); ?>
</div>
<!-- Display a comma separated list of the Post's Categories. -->
<p class="postmetadata"><?php _e( 'Posted in' ); ?> <?php the_category( ', ' ); ?></p>
</div> <!-- closes the first div box -->
<!-- Stop The Loop (but note the "else:" - see next line). -->
<?php endwhile; else : ?>
<!-- The very first "if" tested to see if there were any Posts to -->
<!-- display. This "else" part tells what do if there weren't any. -->
<p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p>
<!-- REALLY stop The Loop. -->
<?php endif; ?>
Loop für Posts
<?php
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'category_name' => $category->name,
'posts_per_page' => 5,
'orderby' => 'title',
'order' => 'ASC'
);
$arr_posts = new WP_Query( $args );
if ( $arr_posts->have_posts() ) :
while ( $arr_posts->have_posts() ) :
$arr_posts->the_post();?>
// Post Content here
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php the_post_thumbnail(); ?>
<?php the_content(); ?>
<?php
endwhile;
endif;
?>
Loop für Kategorien
<?php
$categories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC',
'exclude' => '94', //ID oder Name
) );
foreach( $categories as $category ) {
echo '<li>' .$category->name. '</li>';
}
?>
Loop für Posts pro Kategorie
<?php
$categories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC',
'exclude' => '94'
) );
foreach( $categories as $category ) {
echo '<ul><li>' .$category->name. '</li>';
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'orderby' => 'title',
'order' => 'ASC',
'category_name' => $category->name,
'posts_per_page' => 999999,
);
$arr_posts = new WP_Query( $args );
if ( $arr_posts->have_posts() ) :
while ( $arr_posts->have_posts() ) :
$arr_posts->the_post();?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
endwhile;
endif;
echo '</ul>';
}
?>