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 } ?> <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="description"><?php echo $event['d-description'][1]; ?></div> </div> <?php } ?> </div> </div>
The topic ‘magic fields page template conditional tags’ is closed to new replies.