Title: magic fields page template conditional tags
Last modified: August 19, 2016

---

# magic fields page template conditional tags

 *  Resolved [andywd7](https://wordpress.org/support/users/andywd7/)
 * (@andywd7)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/magic-fields-page-template-conditional-tags/)
 * Hi,
 * I am using magic fields to display menu pages for a bar website. I have set up
   a group with fields in it – drink, price etc… but there are three separate drinks
   page.
 * I have created three templates, one for each type of drink. I am using the same
   group on each page and have just assigned each drink a category. So the code 
   for each page is exactly the same just the category is different. I have pasted
   part of the code below to show how I’m doing it.
 *     ```
       <?php $posts = get_posts('order=ASC&category_name=bottled&numberposts=4&offset=0'); foreach ($posts as $post) : start_wp(); ?>
       	<div class="section">
       	<h2><?php the_title(); ?></h2>
       	<?php static $count1 = 0; if ($count1 == "4") { break; } else { ?>
       	<?php $myEvent = get_group('drinks'); foreach($myEvent as $event){ ?>
       	<div class="d-item">
       		<h3><?php echo $event['d-name'][1]; ?></h3>
       		<div class="price"><?php echo $event['d-price'][1]; ?></div>
       		<div class="description"><?php echo $event['d-description'][1]; ?></div>
       	</div>'
   
       This all works fine but I want to have just the one page with the code on but using conditional tags (I think!?) to display the right category for the right page!?
   
       This is what I thought I should do but it doesn't work!? Could some please help me please!?
   
       Thank you
       ```
   
 * <div class=”column_01″>
    <?php if (is_page(‘cask-ale’)) { ?> <?php $posts = get_posts(‘
   order=ASC&category_name=cask&numberposts=1&offset=0’); foreach ($posts as $post):
   start_wp(); ?> <?php } elseif (is_page(‘keg-beer’)) { ?> <?php $posts = get_posts(‘
   order=ASC&category_name=keg&numberposts=1&offset=0’); foreach ($posts as $post):
   start_wp(); ?> <?php } elseif (is_page(‘keg-beer’)) { ?> <?php $posts = get_posts(‘
   order=ASC&category_name=bottled&numberposts=1&offset=0’); foreach ($posts as 
   $post) : start_wp(); ?> <?php } ?>
 *  <div class=”section”>
    <?php $myEvent = get_group(‘drinks’); foreach($myEvent
   as $event){ ?> <div class=”d-item”> <h3><?php echo $event[‘d-name’][1]; ?></h3
   > <div class=”price”><?php echo $event[‘d-price’][1]; ?></div> <div class=”price”
   ><?php echo $event[‘half’][1]; ?></div> <div class=”description”><?php echo $
   event[‘d-description’][1]; ?></div> </div> <?php } ?> </div> </div>`

Viewing 1 replies (of 1 total)

 *  Thread Starter [andywd7](https://wordpress.org/support/users/andywd7/)
 * (@andywd7)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/magic-fields-page-template-conditional-tags/#post-1747704)
 * Could someone please delete this! I didn’t mean to post it twice!

Viewing 1 replies (of 1 total)

The topic ‘magic fields page template conditional tags’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [conditional](https://wordpress.org/support/topic-tag/conditional/)
 * [group](https://wordpress.org/support/topic-tag/group/)
 * [is_page](https://wordpress.org/support/topic-tag/is_page/)
 * [page](https://wordpress.org/support/topic-tag/page/)
 * [tags](https://wordpress.org/support/topic-tag/tags/)
 * [template](https://wordpress.org/support/topic-tag/template/)

 * 1 reply
 * 1 participant
 * Last reply from: [andywd7](https://wordpress.org/support/users/andywd7/)
 * Last activity: [15 years, 6 months ago](https://wordpress.org/support/topic/magic-fields-page-template-conditional-tags/#post-1747704)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
