Show category name once PHP
-
I am trying to build a restaurant menu structure as a single page, organized by category. I currently have it setup to display all the entries on one page, in groups according to the category. The only thing I haven’t been able to figure out it how to get the category title to only display once. Obviously if I put it in the loop it shows with each entry.
I’ve found this is the code I have so far
<?php if (is_page(menu)) { ?> <?php $recent = new WP_Query("cat=".get_cat_id('menu')."&showposts=50"); while($recent->have_posts()) : $recent->the_post();?> <?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?> <div id="post-<?php the_ID() ?>" class="<?php sandbox_post_class() ?>"> <h2 class="entry-title"><?php the_title() ?></h2> <div class="entry-content"> <?php the_content() ?> <?php wp_link_pages('before=<div class="page-link">' . __( 'Pages:', 'sandbox' ) . '&after=</div>') ?> <?php edit_post_link( __( 'Edit', 'sandbox' ), '<span class="edit-link">', '</span>' ) ?> </div> </div><!-- .post --> <?php endwhile; ?> <?php } ?>
Now I was looking at his page about multiple loops https://codex.www.ads-software.com/The_Loop#Multiple_Loops_in_Action but I can’t figure out how I would go about getting that concept to function with what I’m currently working with. I’m not a PHP guy, so I’m just trying to combine parts here and hope I can get it working.
- The topic ‘Show category name once PHP’ is closed to new replies.