2

within my Genesis child theme I have two different post formats (not types!): 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 Post format 'Gallery' 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' );
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 {
    show standard post
}

Does anybody have a solution for this?

Thanks!

Torben
  • 5,388
  • 12
  • 46
  • 78

1 Answers1

2

I solved it by myself 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

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;
Torben
  • 5,388
  • 12
  • 46
  • 78