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 https://spvgg-1899-leipzig.de/SVLwp/teams/u11-1415/
- The topic ‘Adding dynamic Posts-Loop to Page’ is closed to new replies.