Support

Account

Home Forums Backend Issues (wp-admin) Using ACF with the Genesis Framework

Solving

Using ACF with the Genesis Framework

  • I would like to know if anyone on the forum uses the Genesis Framework for WordPress and if so how you have solved the diplaying of the ACF on this framework.

    I installed the plugin and everything works great on the backend but because of the struture of the Genesis framework I do not know if I should use functions.php or create a template.

    Any help on this would be great.

  • you can use genesis and acf without problems.
    probably best is to use custom template.

    HowTo: a custom post single or archive template for genesis

    <?php
    remove_action( 'genesis_loop', 'genesis_do_loop' );
    add_action( 'genesis_loop', 'your_custom_loop' );
    
    function your_custom_loop() { ?>
    <article itemtype="http://schema.org/CreativeWork" itemscope="itemscope" class="post-<?php print $pageid; ?> page type-page status-publish entry">
    <div class="entry-content" itemprop="text">
    <?php if(have_posts()) : while(have_posts()) : the_post();
    echo get_field('my_acf_fields');
    endwhile; endif;	
    ?>
    </div></article>
    <?php }
    genesis();

    try something like above (of course you need to edit the loop that it fit your needs)

  • Awesome using your code mediawerk in my single-movie.php file helped!
    I really got going with it! Here is the code that I am using:
    (Let me know if there is anything I should adjustment.)

    remove_action( ‘genesis_loop’, ‘genesis_do_loop’ );
    add_action( ‘genesis_loop’, ‘your_custom_loop’ );

    function your_custom_loop() { ?>

    <div class=”movie-content”>
    <?php if(have_posts()) : while(have_posts()) : the_post();

    /* Custom meta boxes */
    echo ‘<div class=”intro-tekst”> ‘ . get_field(‘intro_tekst’) . ‘ </div>’;
    echo ‘<div class=”trailer”> ‘ . get_field(‘trailer’) . ‘ </div>’;
    echo ‘<div class=”synopsis”> ‘ . get_field(‘synopsis’) . ‘ </div>’;

    echo ‘<div class=”teknisk-info”> ‘ . get_field(‘teknisk_info’) . ‘ </div>’;
    echo ‘<div class=”images”> ‘ . get_field(‘images’) . ‘ </div>’;
    endwhile; endif;
    ?>
    </div></div></article>
    <?php }
    genesis();

  • @paaljoachim if you don’t open <article> remove the closing </article>, and remove a closing </div> too. it looks like my original code has also one to much.

    replace </div></div></article> with </div> else it looks fine

    or add something like that <article itemtype="http://schema.org/CreativeWork" itemscope="itemscope" class="post-<?php print $pageid; ?> page type-page status-publish entry"><div class="entry-content" itemprop="text"> above <div class="movie-content">

  • Hi agustinum –

    Depending on what you are doing, you could use a template for a page, or a single for a post, or archive for archives, etc. You just have to make sure to use the right structure hook ( http://genesistutorials.com/visual-hook-guide/ ) and then use either the_field() or echo get_field() to show off you data.

    You can also just put something in your functions file like
    add_action(‘genesis_after_header’,’my_function_name’);
    function my_function_name()
    {
    if(is_page(‘home’) :
    the_field(‘some_field_name’);
    endif;
    }

  • Hey mediawerk

    I changed the code to:

    <article itemtype=”http://schema.org/CreativeWork” itemscope=”itemscope” class=”post-<?php print $pageid; ?> page type-page status-publish entry”>
    <div class=”entry-content” itemprop=”text”>
    
    <div class=”movie-content”>
    <?php if(have_posts()) : while(have_posts()) : the_post();
    
    /* Custom meta boxes */
    echo ‘<div class=”intro-tekst”> ‘ . get_field(‘intro_tekst’) . ‘ </div>';
    echo ‘<div class=”images”> ‘ . get_field(‘images’) . ‘ </div>';
    echo ‘<div class=”trailer”> ‘ . get_field(‘trailer’) . ‘ </div>';
    echo ‘<div class=”teknisk-info”> ‘ . get_field(‘teknisk_info’) . ‘ </div>';
    echo ‘<div class=”synopsis”> ‘ . get_field(‘synopsis’) . ‘ </div>';
    
    endwhile; endif;
    ?>
    </div></div></article>

    It seems to work just fine.
    Why use schema? I thought Genesis has this built in?
    Thanks for adjusting!

  • as far as i know:
    because you replace standard genesis loop with your own loop, you need to add schema at your own again.

    & please when you post code:
    wrap code with code tags (at top over textfield where you write your forum-post-entry you have code mark your code and press that button, than it will be formatted like mine, much better for readability. do that before first submit.)

    (if) you have forgotten that:
    please edit your post, copy-paste code form original and replace existing not formatted code, mark new inserted code and click on code. save/submit forum post again

    edit: thanks for edit your previous post, looks much better now.
    better readable than your first post with code, for example.
    with one exception somehow it add wrong ‘single_quote’ and “double_quote” ‘<div class=” instead of '<div class="`

  • I’m a little late to the party, but I came up with a solution that adds an action to the genesis_entry_content hook.

    My scenario is a site for an artist who makes photographs and paintings. I documented this on my blog:
    http://jeffcohan.com/tek/advanced-custom-fields-genesis/

    HTH. And I’m interested in other approaches.

  • I found this after hours of struggling. Mediawerk you’re my hero!

    My problem now is that when I post with my new custom post template, it works when clicking the permalink, but not on my page which is set to display blog posts.

  • This reply has been marked as private.
  • I’ve set up a field group with two fields and am trying to get a field to show on single posts and am not having any success. Here’s what I have put together from posts on Studiopress forum:

    add_action('genesis_after_post', 'custom_field_after_content');
    
    function custom_field_after_content() {
    if ( is_single() && genesis_get_custom_field('info_box_title') )
    echo genesis_get_custom_field('info_box_title');
    } 

    Is there anything wrong with this? Why am I not able to get even one field to show up at the end of the post content?

  • Here’s 2 different working code snippets which enable you to add custom field content to any Genesis loop using ACF or WordPress custom fields.

    Create a template file in your child theme folder and use the WordPress Template Hierarchy to name the file and add the following code.

    <?php
    /**
     * @author  Brad Dalton
     * @link    https://wpsites.net/web-design/add-custom-field-to-genesis-loop/
     */
    add_action( 'genesis_entry_content', 'function_name', 12 );
    function function_name() {
        $value = get_post_meta( get_the_ID(), 'key', true );
        
        if ( ! empty( $value ) ) {
        
        echo '<div class="your-class">'. $value .'</div>';
        
        }
    }
    genesis();
Viewing 12 posts - 1 through 12 (of 12 total)

The topic ‘Using ACF with the Genesis Framework’ is closed to new replies.