Title: Adding dynamic Posts-Loop to Page
Last modified: August 22, 2016

---

# Adding dynamic Posts-Loop to Page

 *  [mschefers](https://wordpress.org/support/users/mschefers/)
 * (@mschefers)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/adding-dynamic-posts-loop-to-page/)
 * I use the following construct to display post thumbnails of a category-name submitted
   by a custom field “Newskategorie” per page:
 * <div class=”col-md-12 front-page”>
    <?php if(get_field(‘Newskategorie’)) { ?>
   <!– FIELD KATEGORIE NEWS WIDGET–> <div class=”row “> <div class=”col-md-12″> 
   <div class=”front-page-header”> <h2><?php echo the_field(‘Newskategorie’); ?>-
   News</h2> </div> </div> <?php $newskat = the_field(‘Newskategorie’); $recent 
   = new WP_Query( ‘category_slug=’ . $newskat . ‘&posts_per_page=8’ ); while($recent-
   >have_posts()) : $recent->the_post(); ?> <div class=”col-md-6″> <h3>” rel=”bookmark”
   ><?php the_title(); ?></h3> <!– META INFO –> <p class=”the_meta”><?php echo the_time(“
   d-m-y”); ?>   <?php $categories = get_the_category(); $separator = ‘, ‘; $output
   = ”; if($categories){ foreach($categories as $category) { $output .= ‘term_id).'”
   title=”‘ . esc_attr( sprintf( __( “View all posts in %s” ), $category->name )).‘”
   >’.$category->cat_name.’‘.$separator;} echo trim($output, $separator);} ?>  <?
   php the_author_meta(‘display_name’); ?></p> <!– POST IMAGE –> <div class=’the_post_image’
   > ” rel=”bookmark”> <?php if ( has_post_thumbnail() ) { the_post_thumbnail(“thumbnail-
   default”, array(‘class’ => ‘img-responsive’)); } else { ?> <div id=”blank_thumb”
   class=”blank_thumb”></div> <?php } ?> </div><!– the_post_image –> </div> <!– 
   EOF COL-MD-6 –> <?php endwhile; ?> </div> <!– EOF ROW –> <?php } ?> </div>
 * What works: thumbnail function and calling blank thunbmail if no thumbnail image
   is submitted, echoing the Custom Field in Headline, too.
 * But it does not pick the right category (named “U11”,slugged “U11” too).
 * Watch at [http://spvgg-1899-leipzig.de/SVLwp/teams/u11-1415/](http://spvgg-1899-leipzig.de/SVLwp/teams/u11-1415/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [mschefers](https://wordpress.org/support/users/mschefers/)
 * (@mschefers)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/adding-dynamic-posts-loop-to-page/#post-5289725)
 * Tried this one, but failed too. I think this is the mistake.
 * `$recent = new WP_Query( "category_name=" . $newskat . "&posts_per_page=4" );`
 * It just display any category, so i think the variable stays empty.
 * If i change it to
 * `$recent = new WP_Query( "category_name=U11&posts_per_page=4" );` it shows up
   correctly.
 *  Thread Starter [mschefers](https://wordpress.org/support/users/mschefers/)
 * (@mschefers)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/adding-dynamic-posts-loop-to-page/#post-5289747)
 * Just recognized that i used the_field instead of get_post_meta und with this,
   it is working.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Adding dynamic Posts-Loop to Page’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 1 participant
 * Last reply from: [mschefers](https://wordpress.org/support/users/mschefers/)
 * Last activity: [11 years, 8 months ago](https://wordpress.org/support/topic/adding-dynamic-posts-loop-to-page/#post-5289747)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
