Advertisement
marjwyatt

wsk render recipe

Nov 20th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.20 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Single Post Template: Recipes Single
  4.  */
  5. //Pastebin Reference link: http://pastebin.com/ySL2sYE7
  6. //Ref post links:
  7. //http://wordpress.org/support/topic/custom-multiple-query_posts-ids?replies=3
  8. //http://codex.wordpress.org/The_Loop#Multiple_Loops
  9. //http://codex.wordpress.org/Class_Reference/WP_Query#Filters
  10. //http://codex.wordpress.org/Function_Reference/query_posts
  11. //http://codex.wordpress.org/The_Loop#Multiple_Loops
  12. //http://pastie.org/4268087
  13. //https://gist.github.com/2023628
  14. //https://gist.github.com/3907099
  15. //http://codex.wordpress.org/Template_Tags/get_posts
  16. //http://wordpress.org/support/topic/wp_query-loop-after-single-post-before-comments?replies=5
  17. //http://wordpress.org/support/topic/displaying-category-posts-on-a-page-1?replies=2
  18. //http://stackoverflow.com/questions/6838727/getting-post-id-in-wp-query
  19. //http://wordpress.org/support/topic/issues-getting-post-id-in-wp_query?replies=10
  20. //http://www.packtpub.com/article/displaying-posts-pages-using-wordpress-loop
  21. //http://codex.wordpress.org/Function_Reference/add_image_size
  22. //if ( has_post_thumbnail() ) { the_post_thumbnail( 'Post_Single' ); }
  23. // http://codex.wordpress.org/Using_Custom_Fields
  24. // http://codex.wordpress.org/Custom_Fields#Template_Functions
  25. // http://codex.wordpress.org/Function_Reference/get_post_custom
  26. // http://codex.wordpress.org/Function_Reference/get_post_meta
  27. // search for: include custom post meta loop
  28. function recipes_single_image() {
  29.     if ( is_singular() && has_post_thumbnail() ) {
  30.         $img = genesis_get_image( array( 'format' => 'html', 'size' => the_post_thumbnail( 'Post_Single' ), 'attr' => array( 'class' => 'aligncenter Post_Single' ) ) );
  31.     }
  32. }
  33.  
  34. function recipes_microformat() {
  35.     if ( is_singular() && has_post_thumbnail() ) {
  36.         $imgthumb = genesis_get_image( array( 'format' => 'html', 'size' => the_post_thumbnail( 'Post_Thumbnails' ), 'attr' => array( 'class' => 'aligncenter Post_Thumbnails' ) ) );
  37.     }
  38. }
  39.  
  40. remove_action( 'genesis_loop', 'genesis_do_loop' );
  41. add_action( 'genesis_loop', 'recipes_single' );
  42. function recipes_single() {
  43. $query_one = new WP_Query ( array( 'post_type' => 'recipe', 'posts_per_page' => '1' ) );
  44. ?>
  45. <?php genesis_before_content_sidebar_wrap(); ?>
  46. <?php genesis_before_content(); ?>
  47. <?php genesis_before_loop(); ?>
  48. <?php genesis_before_post(); ?>
  49. <?php genesis_before_post_title(); ?>
  50. <?php genesis_post_title(); ?>
  51. <?php genesis_after_post_title(); ?>
  52. <?php genesis_before_post_content(); ?>
  53. <?php if ($query_one->have_posts()) :
  54.     $postid = get_the_id();
  55.     $cats = get_the_category();
  56.     $cat = $cats[0];
  57.     $cat_id = $cat->cat_ID;
  58.     $cat_name = $cat->name;
  59.     $cat_slug = $cat->slug;
  60.     $i=0; // counter
  61.     while ($query_one->have_posts()) : the_post(); $do_not_duplicate = $post->ID; ?>
  62.     <?php if ($i == 0) { ?>
  63.         <div itemscope itemtype ="http://schema.org/Recipe" class="recipe">
  64.             <!--<?php echo $i; ?>-->
  65.             <!--<?php echo "On Cooking Tips Single III Template";?>-->
  66.             <?php the_content(); ?>
  67.             <?php recipes_single_image(); ?>
  68.             <!--<p><?php echo $i; ?></p>-->
  69.             <?php if ( get_post_meta($postid, '_recipetitle', true) ) : ?>
  70.                 <h2 itemprop="name" align="center"><?php echo get_post_meta($postid, "_recipetitle", true); ?></h2>
  71.             <?php endif; ?>
  72.             <?php if ( get_post_meta($postid, '_recipeingred', true) ) :
  73.                 // Get the variable from the database as a string
  74.                 $ingredients = get_post_meta( $postid, "_recipeingred", true );
  75.                 // Break the string up by using the line breaks (carriage returns)
  76.                 $ingredients = explode( "\n", $ingredients );
  77.                 // Echo out the div class & title
  78.                 echo '<div class="ingredients"><h4>Ingredients:</h4>';
  79.                 // Start the unordered list tag
  80.                 echo '<ul>';
  81.                 // Loop through each ingredient since it's now an array thanks to the explode() function
  82.                 foreach( $ingredients as $ingredient ) {
  83.                   // Add the list item open and close tag around each array element
  84.                   echo '<li itemprop="ingredients">' . $ingredient . '</li>';
  85.                   }
  86.                   // Once the loop finishes, close out the unordered list tag
  87.                   echo '</ul>';
  88.                   echo '</div>';
  89.             endif; ?>
  90.             <?php if ( get_post_meta($postid, '_recipeinstructions', true) ) :
  91.                 // Get the variable from the database as a string
  92.                 $instructions = get_post_meta( $postid, "_recipeinstructions", true );
  93.                 // Break the string up by using the line breaks (carriage returns)
  94.                 $instructions = explode( "\n", $instructions );
  95.                 // Echo out the div class & title
  96.                 echo '<div class="instructions"><h4>Instructions:</h4>';
  97.                 // Start the ordered list tag
  98.                 echo '<ol>';
  99.                 // Loop through each ingredient since it's now an array thanks to the explode() function
  100.                 foreach( $instructions as $instruction ) {
  101.                   // Add the list item open and close tag around each array element
  102.                   echo '<li itemprop="recipeInstructions">' . $instruction . '</li>';
  103.                   }
  104.                   // Once the loop finishes, close out the unordered list tag
  105.                   echo '</ol>';
  106.                   echo '</div>';
  107.                 endif; ?>
  108.             <?php if ( get_post_meta($postid, '_recipevariations', true) ) :
  109.                 // Get the variable from the database as a string
  110.                 $variations = get_post_meta( $postid, "_recipevariations", true );
  111.                 // Break the string up by using the line breaks (carriage returns)
  112.                 $variations = explode( "\n", $variations );
  113.                 // Echo out the div class & title
  114.                 echo '<div class="variations"><h4>Variations:</h4>';
  115.                 // Start the ordered list tag
  116.                 echo '<ol>';
  117.                 // Loop through each ingredient since it's now an array thanks to the explode() function
  118.                 foreach( $variations as $variation ) {
  119.                   // Add the list item open and close tag around each array element
  120.                   echo '<li>' . $variation . '</li>';
  121.                   }
  122.                   // Once the loop finishes, close out the unordered list tag
  123.                   echo '</ol>';
  124.                   echo '</div>';
  125.             endif; ?>
  126.             <?php if ( get_post_meta($postid, '_recipenotes', true) ) :
  127.                 // Get the variable from the database as a string
  128.                 $noteparagraphs = get_post_meta( $postid, "_recipenotes", true );
  129.                 // Break the string up by using the line breaks (carriage returns)
  130.                 $noteparagraphs = explode( "\n", $noteparagraphs );
  131.                 // Echo out the div class & title
  132.                 echo '<div class="quicknotes"><h4>Quick Notes:</h4>';
  133.                 foreach( $noteparagraphs as $noteparagraph ) {
  134.                   // Add the list item open and close tag around each array element
  135.                 echo '<p>' . $noteparagraph . '</p>';
  136.                   }
  137.                   // Once the loop finishes, close out the unordered list tag
  138.                 echo '</div>';
  139.             endif; ?>
  140.             <?php if ( get_post_meta($postid, '_recipecook', true) ) : ?>
  141.                 <p itemprop="cookTime" class="cookTime"><span class="hrlabel">Cooking Time:&nbsp;&nbsp;</span><?php echo get_post_meta($postid, "_recipecook", true); ?></p>
  142.             <?php endif; ?>
  143.             <?php if ( get_post_meta($postid, '_recipeprep', true) ) : ?>
  144.                 <p itemprop="prepTime" class="prepTime"><span class="hrlabel">The Recipe Preparation Time:&nbsp;&nbsp;</span><?php echo get_post_meta($postid, "_recipeprep", true); ?></p>
  145.             <?php endif; ?>
  146.             <?php if ( get_post_meta($postid, '_recipeservings', true) ) : ?>
  147.                 <p itemprop="recipeYield" class="recipeYield"><span class="hrlabel">Number of servings (yield):&nbsp;&nbsp;</span><?php echo get_post_meta($postid, "_recipeservings", true); ?></p>
  148.             <?php endif; ?>
  149.             <div class="nutrition">
  150.             <?php if ( get_post_meta($postid, '_recipecalories', true) ) : ?>
  151.                 <p itemprop="calories" class="calories"><span class="hrlabel">Calories per Serving:&nbsp;&nbsp;</span><?php echo get_post_meta($postid, "_recipecalories", true); ?></p>
  152.             <?php endif; ?>
  153.             <?php if ( get_post_meta($postid, '_recipefat', true) ) : ?>
  154.                 <p itemprop="fatContent" class="fat"><span class="hrlabel">Fat Grams per Serving:&nbsp;&nbsp;</span><?php echo get_post_meta($postid, "_recipefat", true); ?></p>
  155.             <?php endif; ?>
  156.             <?php if ( get_post_meta($postid, '_recipeprotein', true) ) : ?>
  157.                 <p itemprop="proteinContent" class="protein"><span class="hrlabel">Protein Grams per Serving:&nbsp;&nbsp;</span><?php echo get_post_meta($postid, "_recipeprotein", true); ?></p>
  158.             <?php endif; ?>
  159.             </div>
  160.             <?php $i++; ?>
  161.         </div><!-- end .entry-content -->
  162.  
  163.     <?php }; ?>
  164.     <!--<?php rewind_posts(); ?> (No effect on output)-->
  165.     <?php if ($i == 1) { ?>
  166.             <div id="accordion-single">
  167.                 <!--<?php echo $i; ?>-->
  168.                 <?php $shrt_cd = "[accordion title='More " . $cat_name . " Recipes from A Well-Seasoned Kitchen']";
  169.                     $query_two = new WP_Query ( array ( 'post_type' => 'recipe', 'category_name' => $cat_name, 'posts_per_page' => '-1' ) );
  170.                     $shrt_cd .= '<ul class="accordion-single-list">';
  171.                     if ($query_two->have_posts()) :
  172.                     while ($query_two->have_posts()) : $query_two->the_post();
  173.                     if( !$post->ID == $do_not_duplicate ) continue;
  174.                         $shrt_cd .= '<li><a href="'.get_permalink().'">';
  175.                         $shrt_cd .= get_the_title();
  176.                         $shrt_cd .= '</a></li>';
  177.                     endwhile; endif;
  178.                     $shrt_cd .= '</ul>';
  179.                     $shrt_cd .= "[/accordion]";
  180.                     echo do_shortcode( $shrt_cd );
  181.                     wp_reset_query();
  182.                 ?>
  183.             </div><!-- accordion-single -->
  184.             <?php $i++; ?>
  185.             <!--<?php echo $i; ?>-->
  186.             <?php if ($i == 2) {
  187.                 genesis_after_post_content();
  188.                 genesis_before_comments();
  189.                 genesis_after_comments();
  190.                 genesis_before_pings();
  191.                 genesis_after_pings();
  192.                 genesis_before_comment_form();
  193.                 genesis_comment_form();
  194.                 genesis_after_comment_form();
  195.             } ?>
  196.             <?php return $wp_query->current_post + 1 < $wp_query->post_count;?>
  197.         <?php }; ?>
  198.     <?php $i++; ?>
  199.     <!--<?php echo $i; ?>-->
  200.     <?php endwhile; ?>
  201.     <?php genesis_after_endwhile(); ?>
  202.     <?php endif; ?>
  203.     <?php genesis_after_loop(); ?>
  204.     <?php genesis_after_content_sidebar_wrap(); ?>
  205.     <?php genesis_before_footer(); ?>
  206.     <?php genesis_after_footer(); ?>
  207. <?php
  208. }
  209. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement