Help with PHP code
-
Hi,
I have installed a theme called Bordeaux from Orange Themes. It is a restaurant theme and there is a food menu section on the theme. We are using this theme to create a website for our Bar. We have live music in the bar from time to time so we use the food menu to display the live bands instead of displaying the food.
So… we have modified the theme to our requirements. But … we have a small problem.
On the home page, we can display “Featured Items” which for us are gigs. But the order of the listings is where we have the problem. We can set the order to Random, by post ID, post date etc. But we would like the order of the live music events (i.e. gigs) listed in the same order as they are listed on the “Full Gig Listings” page.Here is the PHP Code for the Home Page:
<?php /* Template Name: Homepage */ ?> <?php get_header(); ?> <?php include (THEME_INCLUDES . '/top.php'); ?> <?php if(get_option("bordeaux_homepage_slider") != "off" && get_option("bordeaux_homepage_slider")) { ?> <!-- BEGIN .homepage-slider-wrapper --> <div class="homepage-slider-wrapper"> <!-- BEGIN .homepage-slider --> <div class="homepage-slider"> <div id="control"></div> <span class="border-overlay"> </span> <?php if(get_option("bordeaux_homepage_slider") == "on") { ?> <div id="homepage-slider"> <?php $cat = get_option("bordeaux_homepage_slider_cat"); $my_query = new WP_Query('cat='.$cat.'&showposts=5&orderby=menu_order&order=ASC'); ?> <?php if ( $my_query->have_posts() ) : while ( $my_query->have_posts() ) : $my_query->the_post(); ?> <?php $image = get_post_thumb($post->ID,950,350,'bordeaux_slider_image'); ?> <img src="<?php echo $image['src']; ?>" alt="<a href="<?php the_permalink();?>"><b><?php the_title(); ?></b></a><p><?php the_excerpt(); ?></p>" width="950" height="350" /> <?php endwhile; else: ?> <?php endif; ?> </div> <!-- BEGIN .navigation --> <div id="navigation"></div> <?php } else if(get_option("bordeaux_homepage_slider") == "single"){ $homepage_image=get_option("bordeaux_homepage_image"); ?> <div id="homepage-image"> <img src="<?php echo $homepage_image; ?>" width="950" height="350" /> </div> <?php } ?> </div> </div> <?php } ?> <?php $homepage_infoblocks_enabled = get_option("bordeaux_homepage_infoblocks_enabled"); $ib1_title = stripslashes(get_option("ib1_title")); $ib1_image = stripslashes(get_option("ib1_image")); $ib1_url = stripslashes(get_option("ib1_url")); $ib1_text = stripslashes(get_option("ib1_text")); $ib2_title = stripslashes(get_option("ib2_title")); $ib2_image = stripslashes(get_option("ib2_image")); $ib2_url = stripslashes(get_option("ib2_url")); $ib2_text = stripslashes(get_option("ib2_text")); $ib3_title = stripslashes(get_option("ib3_title")); $ib3_image = stripslashes(get_option("ib3_image")); $ib3_url = stripslashes(get_option("ib3_url")); $ib3_text = stripslashes(get_option("ib3_text")); ?> <!-- BEGIN .content-wrapper --> <div class="content-wrapper<?php if(get_option("bordeaux_homepage_slider") == "off") echo " no-content-slider-wrapper"; ?>"> <!-- BEGIN .content --> <div class="content<?php if(get_option("bordeaux_homepage_slider") == "off") echo " no-content-slider-content"; ?>"> <!-- BEGIN .homepage-wrapper --> <div class="homepage-wrapper"> <?php if($homepage_infoblocks_enabled == "on") { ?> <!-- BEGIN .homepage-columns --> <div class="homepage-columns"> <!-- BEGIN .homepage-columns-item --> <div class="homepage-columns-item"> <div class="title"> <div style="background: url(<?php echo $ib1_image;?>) 0 0 no-repeat; padding-left: 68px;"><?php echo $ib1_title;?></div> </div> <div class="text"> <p><?php echo $ib1_text;?></p> <?php if($ib1_url!="") { ?><p class="last"><a href="<?php echo $ib1_url;?>" target="_BLANK" class="more-link"><?php printf ( __( 'Join Here' , 'bordeaux' ));?></a></p><?php } ?> </div> <!-- END .homepage-columns-item --> </div> <!-- BEGIN .homepage-columns-item --> <div class="homepage-columns-item"> <div class="title"> <div style="background: url(<?php echo $ib2_image;?>) 0 0 no-repeat; padding-left: 82px;"><?php echo $ib2_title;?></div> </div> <div class="text"> <p><?php echo $ib2_text;?></p> <?php if($ib2_url!="") { ?><p class="last"><a href="<?php echo $ib2_url;?>" class="more-link"><?php printf ( __( 'More Info' , 'bordeaux' ));?></a></p><?php } ?> </div> <!-- END .homepage-columns-item --> </div> <!-- BEGIN .homepage-columns-item --> <div class="homepage-columns-item last"> <div class="title"> <div style="background: url(<?php echo $ib3_image;?>) 0 0 no-repeat; padding-left: 68px;"><?php echo $ib3_title;?></div> </div> <div class="text"> <p><?php echo $ib3_text;?></p> <?php if($ib3_url!="") { ?><p class="last"><a href="<?php echo $ib3_url;?>" target="_BLANK" class="more-link"><?php printf ( __( 'Click Here' , 'bordeaux' ));?></a></p><?php } ?> </div> <!-- END .homepage-columns-item --> </div> <!-- END .homepage-columns --> </div> <?php } ?> <?php $homepage_footer = get_option("bordeaux_homepage_footer"); if($homepage_footer == "on") { ?> <table width="1050"> <tr> <!-- BEGIN .homepage-about --> <td class="homepage-about"> <?php $homepage_enable_popular_offerings = get_option("bordeaux_homepage_enable_popular_offerings"); if($homepage_enable_popular_offerings == "on") { $popular_menu_title = stripslashes(get_option("bordeaux_popular_menu_title")); $popular_menu_link = get_option("bordeaux_popular_menu_link"); $popular_menu_text = stripslashes(get_option("bordeaux_popular_menu_text")); $orderby = get_option("bordeaux_category_order") ?> <!--- BEGIN Listings Order --> <?php $categories = get_categories("hide_empty=0&taxonomy=menu_card&hierarchical=1"); $options = get_option("bordeaux_category_order"); $order = $options[0]; if($order) { $order_array = explode(",", $order); $i=0; foreach($order_array as $id){ foreach($categories as $n => $category){ if(is_object($category) && $category->term_id == $id){ $categories[$n]->order = $i; $i++; } } foreach($categories as $n => $category){ if(is_object($category) && !isset($category->order)){ $categories[$n]->order = 99999; } } } usort($categories, "bordeaux_category_order_compare"); } ?> <!--- END Listings Order --> <div class="content"> <div class="main-title"> <span><b><?php echo $popular_menu_title; ?></b></span> <a href="<?php echo get_page_link(get_menucard_page()); ?>"><?php printf ( __( 'full gig list' , 'bordeaux' ));?></a> </div> <p class="caps"><?php echo $popular_menu_text; ?></p> <div class="main-spacer"> </div> <!-- BEGIN .menu-display-1-wrapper --> <div class="menu-display-1-wrapper"> <div class="menu-display-1"> <?php $args = array( 'numberposts' => 10, 'offset' => 0, 'orderby' => 'rand', 'order' => 'DESC', 'meta_key' => 'bordeaux_popular_offering', 'meta_value' => '1', 'post_type' => 'menu-card', 'post_status' => 'publish' ); $myposts = get_posts( $args ); $count=0; global $post; foreach( $myposts as $post ) : setup_postdata($post); $count++; $thePostID = $post->ID; $price=get_post_meta($thePostID, 'bordeaux_price', true); if(!$price) $price=0; $boderaux_currency=get_option('boderaux_currency_category'); $image = get_post_thumb($thePostID,180,120); ?> <div class="item"> <h5><?php the_title(); ?></h5> <a href="<?php the_permalink();?>" class="image"> <img src="<?php echo $image['src'];?>" alt="<?php the_title(); ?>" width="180" height="120" /> </a> <p><?php the_excerpt(); ?></p> <p><a href="<?php the_permalink();?>" class="more-link"><?php printf ( __( 'Read more' , 'bordeaux' ));?></a></p> </div> <?php if($count>=4) { echo ""; $count=0; } ?> <?php endforeach; ?> <div class="clear"></div> </div> <!-- END .menu-display-1-wrapper --> </div> <p class="show-all"><a href="<?php echo get_page_link(get_menucard_page()); ?>"><span><?php printf ( __( 'Show Full Events List' , 'bordeaux' ));?></span></a></p> </div> <?php } ?> <?php $footer_post = get_option("bordeaux_homepage_footer_post"); if($footer_post && $homepage_enable_popular_offerings == "off") { $args=array( 'p' => $footer_post, 'post_type' => 'page' ); $the_query = new WP_Query($args); global $more; $more = false; if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?> <div class="content"> <div class="main-title"> <span><b><?php the_title();?></b></span> <a href="<?php the_permalink();?>"><?php printf ( __( 'read more' , 'bordeaux' ));?></a> </div> <p class="caps"> <?php add_filter('the_content','page_read_more');?> <?php add_filter('the_content', 'big_first_char', 5); ?> <?php the_content(); ?> </p> <div class="main-spacer"> </div> </div> <?php endwhile; else: ?> <p><?php printf ( __( 'No posts where found' , 'bordeaux' ));?></p> <?php endif; ?> <?php } ?> </td> <!-- END .homepage-about --> <td class="spacer"></td> <!-- BEGIN .events --> <!-- END .events --> </tr> </table> <?php } ?> <!-- END .homepage-wrapper --> </div> <!-- END .content --> </div> <!-- END .content-wrapper --> </div> <?php get_footer(); ?>Now here is the code for the Full listings Page:
<?php /* Template Name: Menu Card */ ?> <?php get_header(); ?> <?php include (THEME_INCLUDES . '/top.php'); ?> <?php $slider_enabled=get_option('bordeaux_slider_enabled'); if ($slider_enabled == "on") { include (THEME_INCLUDES . '/slider.php'); } else if ($slider_enabled == "off") { echo "<div class=\"no-content-slider\"> </div>"; } $current_page=$_GET['page']; if($current_page && is_numeric ($current_page)) { $page=$current_page; } else { $page=1;} $categories = get_categories("hide_empty=0&taxonomy=menu_card&hierarchical=1"); $options = get_option("bordeaux_category_order"); $order = $options[0]; if($order) { $order_array = explode(",", $order); $i=0; foreach($order_array as $id){ foreach($categories as $n => $category){ if(is_object($category) && $category->term_id == $id){ $categories[$n]->order = $i; $i++; } } foreach($categories as $n => $category){ if(is_object($category) && !isset($category->order)){ $categories[$n]->order = 99999; } } } usort($categories, "bordeaux_category_order_compare"); } ?> <!-- BEGIN .content-wrapper --> <div class="content-wrapper<?php if($slider_enabled == "off") echo " no-content-slider-wrapper";?>"> <!-- BEGIN .content --> <div class="content<?php if($slider_enabled == "off") echo " no-content-slider-content";?>"> <?php if($categories) { ?> <table class="menu-card"> <tr> <td class="navigation"><a href="#" class="previous" id="card-prev"> </a></td> <td class="menu-card-content-wrapper"> <div class="top"> </div> <!-- BEGIN .content-wrapper --> <div class="content-wrapper"> <!-- BEGIN .card-container --> <div id="card-container" activepage="<?php echo $page;?>"> <!-- BEGIN .card-slider --> <div class="content" id="card-slider"> <?php $pageCount=0; $sliderCount=1; foreach($categories as $category) { if($category->parent==0) { $pageCount++; if($pageCount==1) { ?> <!-- BEGIN .card-page --> <div class="card-page" id="cardpageid-<?php echo $sliderCount;?>"> <!-- BEGIN .left-side --> <div class="left-side"> <div class="menu-card-title"><?php printf ( __( 'Vintage Bar' , 'bordeaux' ));?></div> <?php } if($pageCount%2==1 && $pageCount!=1) { $sliderCount++; ?> <!-- END .right-side --> </div> <div class="clear"></div> <!-- END .card-page --> </div> <!-- BEGIN .card-page --> <div class="card-page" id="cardpageid-<?php echo $sliderCount;?>"> <!-- BEGIN .left-side --> <div class="left-side"> <div class="menu-card-title"><?php printf ( __( 'Menu Card' , 'bordeaux' ));?></div> <?php } elseif($pageCount%2==0) { ?> <!-- END .left-side --> </div> <!-- BEGIN .right-side --> <div class="right-side"> <div class="menu-card-link"><a href="<?php echo get_page_link(get_reservation_page()); ?>"><?php printf ( __( 'check & order your Reservation' , 'bordeaux' ));?></a></div> <?php } echo "<h3>".$category->name."</h3>"; //*** category description ***// $cat_description=$category->description; //echo $cat_description; $sub_cats=get_categories("hide_empty=1&taxonomy=menu_card&child_of=$category->cat_ID"); if($sub_cats) { $cat=$category->cat_ID; $order = $options[$cat]; if($order){ $order_array = explode(",", $order); $i=0; foreach($order_array as $id){ foreach($sub_cats as $n => $category){ if(is_object($category) && $category->term_id == $id){ $sub_cats[$n]->order = $i; $i++; } } foreach($sub_cats as $n => $category){ if(is_object($category) && !isset($category->order)){ $sub_cats[$n]->order = 99999; } } } usort($sub_cats, "bordeaux_category_order_compare"); } foreach($sub_cats as $sub_cat) { echo "<h4>$sub_cat->name</h4>"; //*** category description ***// $scat_description=$sub_cat->description; //echo $scat_description; $slug=$sub_cat->slug; $args = array( 'tax_query' => array( array( 'taxonomy' => 'menu_card', 'field' => 'slug', 'terms' => $slug, ) ), 'posts_per_page'=>100, 'orderby'=>'menu_order', 'order'=>'DESC' ); $my_query = new WP_Query( $args); if ( $my_query->have_posts() ) : while ( $my_query->have_posts() ) : $my_query->the_post(); $thePostID = $post->ID; $image = get_post_thumb($thePostID,54,54,"menu_item_slider"); $image_hover = get_post_thumb($thePostID,180,180,"menu_item_slider_hover"); $price=get_post_meta($thePostID, 'bordeaux_price', true); if(!$price) $price=0; $boderaux_currency=get_option('boderaux_currency_category'); $get_the_content=get_the_content(); preg_match('|\[ingredients title="(.*)"\](.*)\[\/ingredients\]|si', $get_the_content, $content); ?> <table class="item"> <tr> <td class="image"><a href="<?php the_permalink(); ?>" class="tTip" title="<img src="<?php echo $image_hover['src'];?>" alt="" width="180" height="180" />"><img src="<?php echo $image['src'];?>" alt="" width="54" height="54" /></a></td> <td class="text"> <p class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p> <p class="description"><?php if(isset($content[2]) && $content[2]) { echo WordLimiter(strip_tags($content[2])); } else { the_excerpt(); } ?></p> </td> <td class="menu-price"><p><?php echo $boderaux_currency.$price;?></p></td> </tr> </table> <?php endwhile; else: endif; } //end foreach } //end if sub_cats }//end if } // end foreach ?> <!-- END .right-side --> </div> <div class="clear"></div> <!-- END .card-page --> </div> <!-- END .card-slider --> </div> <!-- END .card-container --> </div> <!-- END .content-wrapper --> </div> </td> <!-- END .homepage-about --> <td class="navigation"><a href="#" class="next" id="card-next"> </a></td> </tr> <tr> <td></td> <td class="menu-card-content-wrapper-bottom"></td> <td></td> </tr> </table> <?php $count_posts = wp_count_posts('menu-card'); $published_posts = $count_posts->publish; } else if($published_posts==0){ echo "<span style=\"color:#fff; font-size:14pt;\">You need to add at least one post in the menu card, you can do it <a style=\"color:#fff; font-size:14pt;\" href=\"".admin_url()."post-new.php?post_type=menu-card\">here</a>!</span>"; } else if(!$categories){ echo "<span style=\"color:#fff; font-size:14pt;\">You need to add at least one category and one sub-category for the menu card, you can do it <a style=\"color:#fff; font-size:14pt;\" href=\"".admin_url()."post-new.php?post_type=menu-card\">here</a>!</span>"; } ?> <!-- END .content --> </div> <!-- END .content-wrapper --> </div> <?php get_footer(); ?>We don’t know too much about PHP code so we really would like if someone could fix this for us.
Thanks
The topic ‘Help with PHP code’ is closed to new replies.