Community Forums › Forums › Archived Forums › Design Tips and Tricks › How to use a different template for post format 'gallery'?
- This topic has 10 replies, 2 voices, and was last updated 9 years, 1 month ago by Brad Dalton.
-
AuthorPosts
-
March 5, 2015 at 1:56 am #143249trashParticipant
Hey,
within my Genesis child theme I have two different post formats: Standard and Gallery.When the user selects the Gallery he gets offered additional fields via the Advanced Custom Fields plugin. I know need to change the template of the Gallery Post format in order to pull the data from the ACF plugin.
How can I do this with genesis?
I tried it with:
remove_action( 'genesis_loop', 'genesis_do_loop' ); add_action( 'genesis_loop', 'loop_helper' ); /** Add support for Genesis Grid Loop */ function loop_helper() { if ( has_post_format( 'gallery' )) { echo 'this is the gallery format'; } else { genesis_standard_loop(); } }
But this is not working as it just shows "this is the gallery format" and nothing else. I am looking for something like:
if ( has_post_format( 'gallery' )) { get_template_part(‘content’,get_post_format()); } else { genesis_standard_loop(); }
Does anybody have a solution for this?
Thanks!
March 5, 2015 at 2:36 am #143256Brad DaltonParticipantMarch 5, 2015 at 2:40 am #143257trashParticipantHey braddalton,
yep - but how? I tried it withget_template_part(‘content’,get_post_format());
but how can I take this template into consideration in my loop?March 5, 2015 at 2:43 am #143258trashParticipantMeanwhile I started with creating a fully customized loop including another template when "gallery" is set:
`$query = new WP_Query($arg);
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post();if ( has_post_format( 'gallery' )) {
get_template_part('content',get_post_format());
} else {
?>
<article <?=post_class();?>>
<header class="entry-header">
<h2 class="entry-title" itemprop="headline">
<a href="<?=the_permalink();?>" rel="bookmark"><?=the_title();?></a>
</h2>
</header>
<div class="entry-content" itemprop="text">
<p><?=the_content();?></p>
</div>
</article>
<?php
}//else
endwhile;
endif;`But how can I use include the post meta info like date/author into the code above in order to keep the genesis meta hooks etc?
March 5, 2015 at 2:54 am #143261Brad DaltonParticipantJust to confirm, you want to use a custom template which includes ACF fields only on posts using the gallery post format?
Here's my solution http://wpsites.net/wordpress-themes/load-custom-single-post-template-for-specific-post-format-in-genesis/
March 5, 2015 at 2:59 am #143263trashParticipantYep, exactly.
March 5, 2015 at 3:33 am #143265trashParticipantI also tried it with this:
add_filter('the_content','test_filter'); function test_filter($content) { if ( get_post_format() == 'gallery' ) get_template_part('content',get_post_format()); }//function
But this seems to be executed not only on post content, but for general content. So the content for the post got executed within the post and directly after the
<body>
I think the solution with the filter for the_content is perfect, but I need to ensure that this is only taken into consideration within the loop. So I have to create a fully custom loop, right?
March 5, 2015 at 3:39 am #143266Brad DaltonParticipantMarch 5, 2015 at 3:44 am #143268trashParticipantThanks, but I thought that this forum is for those who paid for Genesis and need help. I do not want to register on another website and pay $37.
March 5, 2015 at 3:51 am #143270trashParticipantFor everyone else - I solved it and this seems to be working fine:
functions.php:
remove_action( 'genesis_entry_content', 'genesis_do_post_content' ); add_action('genesis_entry_content', 'custom_entry_content'); function custom_entry_content() { if (get_post_format() == 'gallery' ) { get_template_part('content',get_post_format()); } else { the_content(); } }//function
Within the content-gallery.php:
<?php // check if the repeater field has rows of data if( have_rows('gallery_block') ): // loop through the rows of data while ( have_rows('gallery_block') ) : the_row(); ?> <div class="gallery-block-wrapper"> <div class="gallery-block-img"> <img src="<?php the_sub_field( 'gallery_block_picture' ); ?>" /> </div> <div class="gallery-block-headline"> <?php the_sub_field( 'gallery_block_headline' ); ?> </div> <div class="gallery-block-text"> <?php the_sub_field( 'gallery_block_content' ); ?> </div> </div><!-- gallery-block-wrapper --> <? endwhile; endif;
March 5, 2015 at 4:03 am #143272Brad DaltonParticipant -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.