Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Single Post Template: Recipes Single
- */
- //Pastebin Reference link: http://pastebin.com/ySL2sYE7
- //Ref post links:
- //http://wordpress.org/support/topic/custom-multiple-query_posts-ids?replies=3
- //http://codex.wordpress.org/The_Loop#Multiple_Loops
- //http://codex.wordpress.org/Class_Reference/WP_Query#Filters
- //http://codex.wordpress.org/Function_Reference/query_posts
- //http://codex.wordpress.org/The_Loop#Multiple_Loops
- //http://pastie.org/4268087
- //https://gist.github.com/2023628
- //https://gist.github.com/3907099
- //http://codex.wordpress.org/Template_Tags/get_posts
- //http://wordpress.org/support/topic/wp_query-loop-after-single-post-before-comments?replies=5
- //http://wordpress.org/support/topic/displaying-category-posts-on-a-page-1?replies=2
- //http://stackoverflow.com/questions/6838727/getting-post-id-in-wp-query
- //http://wordpress.org/support/topic/issues-getting-post-id-in-wp_query?replies=10
- //http://www.packtpub.com/article/displaying-posts-pages-using-wordpress-loop
- //http://codex.wordpress.org/Function_Reference/add_image_size
- //if ( has_post_thumbnail() ) { the_post_thumbnail( 'Post_Single' ); }
- // http://codex.wordpress.org/Using_Custom_Fields
- // http://codex.wordpress.org/Custom_Fields#Template_Functions
- // http://codex.wordpress.org/Function_Reference/get_post_custom
- // http://codex.wordpress.org/Function_Reference/get_post_meta
- // search for: include custom post meta loop
- function recipes_single_image() {
- if ( is_singular() && has_post_thumbnail() ) {
- $img = genesis_get_image( array( 'format' => 'html', 'size' => the_post_thumbnail( 'Post_Single' ), 'attr' => array( 'class' => 'aligncenter Post_Single' ) ) );
- }
- }
- function recipes_microformat() {
- if ( is_singular() && has_post_thumbnail() ) {
- $imgthumb = genesis_get_image( array( 'format' => 'html', 'size' => the_post_thumbnail( 'Post_Thumbnails' ), 'attr' => array( 'class' => 'aligncenter Post_Thumbnails' ) ) );
- }
- }
- remove_action( 'genesis_loop', 'genesis_do_loop' );
- add_action( 'genesis_loop', 'recipes_single' );
- function recipes_single() {
- $query_one = new WP_Query ( array( 'post_type' => 'recipe', 'posts_per_page' => '1' ) );
- ?>
- <?php genesis_before_content_sidebar_wrap(); ?>
- <?php genesis_before_content(); ?>
- <?php genesis_before_loop(); ?>
- <?php genesis_before_post(); ?>
- <?php genesis_before_post_title(); ?>
- <?php genesis_post_title(); ?>
- <?php genesis_after_post_title(); ?>
- <?php genesis_before_post_content(); ?>
- <?php if ($query_one->have_posts()) :
- $postid = get_the_id();
- $cats = get_the_category();
- $cat = $cats[0];
- $cat_id = $cat->cat_ID;
- $cat_name = $cat->name;
- $cat_slug = $cat->slug;
- $i=0; // counter
- while ($query_one->have_posts()) : the_post(); $do_not_duplicate = $post->ID; ?>
- <?php if ($i == 0) { ?>
- <div itemscope itemtype ="http://schema.org/Recipe" class="recipe">
- <!--<?php echo $i; ?>-->
- <!--<?php echo "On Cooking Tips Single III Template";?>-->
- <?php the_content(); ?>
- <?php recipes_single_image(); ?>
- <!--<p><?php echo $i; ?></p>-->
- <?php if ( get_post_meta($postid, '_recipetitle', true) ) : ?>
- <h2 itemprop="name" align="center"><?php echo get_post_meta($postid, "_recipetitle", true); ?></h2>
- <?php endif; ?>
- <?php if ( get_post_meta($postid, '_recipeingred', true) ) :
- // Get the variable from the database as a string
- $ingredients = get_post_meta( $postid, "_recipeingred", true );
- // Break the string up by using the line breaks (carriage returns)
- $ingredients = explode( "\n", $ingredients );
- // Echo out the div class & title
- echo '<div class="ingredients"><h4>Ingredients:</h4>';
- // Start the unordered list tag
- echo '<ul>';
- // Loop through each ingredient since it's now an array thanks to the explode() function
- foreach( $ingredients as $ingredient ) {
- // Add the list item open and close tag around each array element
- echo '<li itemprop="ingredients">' . $ingredient . '</li>';
- }
- // Once the loop finishes, close out the unordered list tag
- echo '</ul>';
- echo '</div>';
- endif; ?>
- <?php if ( get_post_meta($postid, '_recipeinstructions', true) ) :
- // Get the variable from the database as a string
- $instructions = get_post_meta( $postid, "_recipeinstructions", true );
- // Break the string up by using the line breaks (carriage returns)
- $instructions = explode( "\n", $instructions );
- // Echo out the div class & title
- echo '<div class="instructions"><h4>Instructions:</h4>';
- // Start the ordered list tag
- echo '<ol>';
- // Loop through each ingredient since it's now an array thanks to the explode() function
- foreach( $instructions as $instruction ) {
- // Add the list item open and close tag around each array element
- echo '<li itemprop="recipeInstructions">' . $instruction . '</li>';
- }
- // Once the loop finishes, close out the unordered list tag
- echo '</ol>';
- echo '</div>';
- endif; ?>
- <?php if ( get_post_meta($postid, '_recipevariations', true) ) :
- // Get the variable from the database as a string
- $variations = get_post_meta( $postid, "_recipevariations", true );
- // Break the string up by using the line breaks (carriage returns)
- $variations = explode( "\n", $variations );
- // Echo out the div class & title
- echo '<div class="variations"><h4>Variations:</h4>';
- // Start the ordered list tag
- echo '<ol>';
- // Loop through each ingredient since it's now an array thanks to the explode() function
- foreach( $variations as $variation ) {
- // Add the list item open and close tag around each array element
- echo '<li>' . $variation . '</li>';
- }
- // Once the loop finishes, close out the unordered list tag
- echo '</ol>';
- echo '</div>';
- endif; ?>
- <?php if ( get_post_meta($postid, '_recipenotes', true) ) :
- // Get the variable from the database as a string
- $noteparagraphs = get_post_meta( $postid, "_recipenotes", true );
- // Break the string up by using the line breaks (carriage returns)
- $noteparagraphs = explode( "\n", $noteparagraphs );
- // Echo out the div class & title
- echo '<div class="quicknotes"><h4>Quick Notes:</h4>';
- foreach( $noteparagraphs as $noteparagraph ) {
- // Add the list item open and close tag around each array element
- echo '<p>' . $noteparagraph . '</p>';
- }
- // Once the loop finishes, close out the unordered list tag
- echo '</div>';
- endif; ?>
- <?php if ( get_post_meta($postid, '_recipecook', true) ) : ?>
- <p itemprop="cookTime" class="cookTime"><span class="hrlabel">Cooking Time: </span><?php echo get_post_meta($postid, "_recipecook", true); ?></p>
- <?php endif; ?>
- <?php if ( get_post_meta($postid, '_recipeprep', true) ) : ?>
- <p itemprop="prepTime" class="prepTime"><span class="hrlabel">The Recipe Preparation Time: </span><?php echo get_post_meta($postid, "_recipeprep", true); ?></p>
- <?php endif; ?>
- <?php if ( get_post_meta($postid, '_recipeservings', true) ) : ?>
- <p itemprop="recipeYield" class="recipeYield"><span class="hrlabel">Number of servings (yield): </span><?php echo get_post_meta($postid, "_recipeservings", true); ?></p>
- <?php endif; ?>
- <div class="nutrition">
- <?php if ( get_post_meta($postid, '_recipecalories', true) ) : ?>
- <p itemprop="calories" class="calories"><span class="hrlabel">Calories per Serving: </span><?php echo get_post_meta($postid, "_recipecalories", true); ?></p>
- <?php endif; ?>
- <?php if ( get_post_meta($postid, '_recipefat', true) ) : ?>
- <p itemprop="fatContent" class="fat"><span class="hrlabel">Fat Grams per Serving: </span><?php echo get_post_meta($postid, "_recipefat", true); ?></p>
- <?php endif; ?>
- <?php if ( get_post_meta($postid, '_recipeprotein', true) ) : ?>
- <p itemprop="proteinContent" class="protein"><span class="hrlabel">Protein Grams per Serving: </span><?php echo get_post_meta($postid, "_recipeprotein", true); ?></p>
- <?php endif; ?>
- </div>
- <?php $i++; ?>
- </div><!-- end .entry-content -->
- <?php }; ?>
- <!--<?php rewind_posts(); ?> (No effect on output)-->
- <?php if ($i == 1) { ?>
- <div id="accordion-single">
- <!--<?php echo $i; ?>-->
- <?php $shrt_cd = "[accordion title='More " . $cat_name . " Recipes from A Well-Seasoned Kitchen']";
- $query_two = new WP_Query ( array ( 'post_type' => 'recipe', 'category_name' => $cat_name, 'posts_per_page' => '-1' ) );
- $shrt_cd .= '<ul class="accordion-single-list">';
- if ($query_two->have_posts()) :
- while ($query_two->have_posts()) : $query_two->the_post();
- if( !$post->ID == $do_not_duplicate ) continue;
- $shrt_cd .= '<li><a href="'.get_permalink().'">';
- $shrt_cd .= get_the_title();
- $shrt_cd .= '</a></li>';
- endwhile; endif;
- $shrt_cd .= '</ul>';
- $shrt_cd .= "[/accordion]";
- echo do_shortcode( $shrt_cd );
- wp_reset_query();
- ?>
- </div><!-- accordion-single -->
- <?php $i++; ?>
- <!--<?php echo $i; ?>-->
- <?php if ($i == 2) {
- genesis_after_post_content();
- genesis_before_comments();
- genesis_after_comments();
- genesis_before_pings();
- genesis_after_pings();
- genesis_before_comment_form();
- genesis_comment_form();
- genesis_after_comment_form();
- } ?>
- <?php return $wp_query->current_post + 1 < $wp_query->post_count;?>
- <?php }; ?>
- <?php $i++; ?>
- <!--<?php echo $i; ?>-->
- <?php endwhile; ?>
- <?php genesis_after_endwhile(); ?>
- <?php endif; ?>
- <?php genesis_after_loop(); ?>
- <?php genesis_after_content_sidebar_wrap(); ?>
- <?php genesis_before_footer(); ?>
- <?php genesis_after_footer(); ?>
- <?php
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement