Hallo, ich habe mir ein kleines Rezeptbuch mit Custom Post Types und custom Fields erstellt. Nun bearbeite ich gerade die Single Seite für den Post Type. In dieser lade ich den Beitragstext und darunter sollte eine Tabelle mit den Zutaten (Aromen) ausgegeben werden. Das funktioniert auch schon, doch werden mir auch Zeilen der Tabelle angezeigt, die keinen Inhalt haben. Dies würde ich gerne ändern, sodass nur Zeilen mit Inhalt ausgegeben werden. Was ich nun heraus gefunden habe, dass ich wohl eine Foreach Schleife ausführen muss, doch irgendwie verstehe ich das nicht ganz wie ich die einbaue und bräuchte etwas Hilfe.
PHP
<?php
/*
* Template Name: Single Rezept
*/
get_header();
$container = get_theme_mod( 'understrap_container_type' );
?>
<div class="wrapper" id="page-wrapper">
<div class="<?php echo esc_attr( $container ); ?>" id="content">
<div class="row">
<div
class="<?php if ( is_active_sidebar( 'right-sidebar' ) ) : ?>col-md-8<?php else : ?>col-md-12<?php endif; ?> content-area"
id="primary">
<main class="site-main" id="main" role="main">
<h2 ><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="entry"><?php the_content(); ?></div>
<?php endwhile; endif; ?>
<div class=card style="width:300px;">
<table class="table table-bordered table-sm table-striped">
<thead>
<tr>
<th class="col-1 text-dark">%</th>
<th class="col text-dark">Aroma</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php the_field( 'aroma_1a' );?></td>
<td><?php the_field( 'aroma_1b' );?></td>
</tr>
<tr>
<td><?php the_field( 'aroma_2a' );?></td>
<td><?php the_field( 'aroma_2b' );?></td>
</tr>
<tr>
<td><?php the_field( 'aroma_3a' );?></td>
<td><?php the_field( 'aroma_3b' );?></td>
</tr>
<tr>
<td><?php the_field( 'aroma_4a' );?></td>
<td><?php the_field( 'aroma_4b' );?></td>
</tr>
<tr>
<td><?php the_field( 'aroma_5a' );?></td>
<td><?php the_field( 'aroma_5b' );?></td>
</tr>
</tbody>
</table>
</div>
<div class="card">
<div class="card-header">
Bewertung
</div>
<div class="card-body">
<?php if(function_exists('the_ratings')) { the_ratings(); } ?>
</div>
</div>
<?php comments_template( '', true ); ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar( 'right' ); ?>
</div><!-- .row -->
</div><!-- Container end -->
</div><!-- Wrapper end -->
<?php get_footer(); ?>
Alles anzeigen