• Resolved berttervoert

    (@berttervoert)


    I made a template to show the four latest recipes on my frontpage. But I seem to be doing something wrong. I use the image (wprm), the titel of the post (wp) and the summary (wprm).
    While it shows the titels correctly for each post, it shows the image and summary of the last post on all posts. So I seem to be doing something wrong. The site is running on localhost, so I can’t send a link, but this is the code I’m using:

    <div class="fp-recipes-container">
    	<div class="fp-recipes-container-titel">
    		MEEST RECENT: BAKKEN - ZOET
    	</div>
    	<div class="fp-spacer-hori-in-container">
    	</div>
    	<?php $myCatQuery = new WP_Query ( 'category_name=bakkenzoet&posts_per_page=4' );
    			if ( $myCatQuery->have_posts() ){
    				while ( $myCatQuery->have_posts() ){
    					echo '<div class="fp-recipes-blok">';
    					$myCatQuery->the_post();
    					echo '<div class="fp-recipes-blok_recipe-image">';
    						echo do_shortcode( '[wprm-recipe-image]' );
    					echo '</div>';
    					echo '<div class="fp-recipes-blok_recipe-titel">';
    						?><a href="<?php the_permalink(); ?>"><?php the_title() ?></a> <?php ;
    					echo '</div>';
    					echo '<div class="fp-spacer-hori-in-blok"></div>';
    					echo '<div class="fp-recipes-blok_recipe-summary">';
    						echo do_shortcode( '[wprm-recipe-summary]' );
    					echo '</div>';
    				echo '</div>';
    					
    				}
                            wp_reset_postdata();
    			} else {
    				echo '<div class="fp-no-post-center">';
    				echo 'Sorry, (nog) geen posts gevonden voor deze categorie.';
    				echo '</div>';
    			}
    			 
    	?>
    </div>
    

    I hope you can give me an idea where I go wrong here.

    Bert.

    • This topic was modified 5 years, 8 months ago by berttervoert.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Brecht

    (@brechtvds)

    Hi Bert,

    Try using this code to get the ID of the recipe you want to display:
    https://help.bootstrapped.ventures/article/110-access-recipes-in-a-post-via-code

    Then you can add the id=123 attribute to the shortcode to make sure it displays the correct recipe.

    Thread Starter berttervoert

    (@berttervoert)

    Thank you for your reply. I managed to get it working now. The code now is as follows:

    	<div class="fp-recipes-container-titel">
    		MEEST RECENT: KOKEN
    	</div>
    	<div class="fp-spacer-hori-in-container">
    	</div>
    	<?php $myCatQuery = new WP_Query ( 'category_name=koken&posts_per_page=4' );
    			if ( $myCatQuery->have_posts() ) {
    				while ( $myCatQuery->have_posts() ){
    					echo '<div class="fp-recipes-blok">';
    					$myCatQuery->the_post();
    					// Get the recipes inside the current post.
    					$recipes = WPRM_Recipe_Manager::get_recipe_ids_from_post();
    					// Access the first recipe, if there is one.
    					if ( isset( $recipes[0] ) ) {
    						$recipe_id = $recipes[0];
    						$recipe = WPRM_Recipe_Manager::get_recipe( $recipe_id );
    					}
    					echo '<div class="fp-recipes-blok_recipe-image">';
    					echo do_shortcode( '[wprm-recipe-image id="' . $recipe_id . '"]' );
    					echo '</div>';
    					echo '<div class="fp-recipes-blok_recipe-titel">';
    						?><a href="<?php the_permalink(); ?>"><?php the_title() ?></a> <?php ;
    					echo '</div>';
    					echo '<div class="fp-spacer-hori-in-blok"></div>';
    					echo '<div class="fp-recipes-blok_recipe-summary">';
    						echo do_shortcode( '[wprm-recipe-summary id="' . $recipe_id . '"]' );
    					echo '</div>';
    				echo '</div>';
    					
    				}
    			wp_reset_postdata(); 
    			} else {
    				echo '<div class="fp-no-post-center">';
    				echo 'Sorry, (nog) geen posts gevonden voor deze categorie.';
    				echo '</div>';
    			}
    	?>
    </div>
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Displaying content of last recipe only on frontpage’ is closed to new replies.