• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Displaying custom fields above the content

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Displaying custom fields above the content

This topic is: resolved

Tagged: Custom fields, Custom Post Type

  • This topic has 11 replies, 2 voices, and was last updated 9 years, 8 months ago by lucaslem.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • September 18, 2013 at 4:32 pm #63296
    lucaslem
    Member

    Hi all,

    I have created a custom post type called workshops which has :

    1. a title (genesis_entry_header)
    2. an intro block (custom field)
    3. registration details (custom field)
    4. workshop content (genesis_entry_content)

    I created the custom fields using ACF and I have followed their documentation in to display the fields' content in front en, and here is my code in workshops-single.php:

    <?php
    
    /**
     * Template Name: workshop
     * Description: Used as template for workshop custom post type 
     */
    
    add_action( 'genesis_entry_content', 'ismh_workshops_acf' );
    function ismh_workshops_acf() {
        the_field('workshop_intro');
    	the_field('registration_details');
    }
    
    genesis();

    I would like the intro block and the registration details to appear between the title and the content, but it's currently appearing at the bottom . I am not certain if this requires a custom loop or if there are some more straight-forward ways to remove and re-add content in correct order via hooks etc. I am new to all of this, but learning quickly. Thanks for any advice.

    September 18, 2013 at 4:53 pm #63299
    Brad Dalton
    Participant

    You can change the hook positions and add a 3rd parameter for positioning priority.

    Here's a simple explanation http://wpsites.net/web-design/3rd-parameter-action-hooks/

    Here's the new HTML 5 hooks and markup http://genesistutorials.com/visual-hook-guide/

    There's also a hook chart with the 3rd parameter included but i couldn't find it. Not sure you'll need it but the hook will ned to be changed to display before the content or before the loop.

    add_action( 'genesis_entry_header', 'ismh_workshops_acf' );
    

    David Chu who volunteers on these forums has a good understanding of custom fields http://davidchu.net/blog/wordpress-custom-field-genesis-framework/

    Here's a good tutorial also http://kevinshoffner.com/wordpress/genesis/displaying-custom-fields-for-genesis/

    You can also hook in custom fields from your child thees functions file. No need to add them in a template.


    Tutorials for StudioPress Themes & WooCommerce.

    September 19, 2013 at 2:09 pm #63431
    lucaslem
    Member

    Hi Brad, thanks so much for the resources. I had actually been reading a bunch of your tutorials (wow, priceless, thanks so much) and then it occurred to me to try something. If my goal is to get the content to display between the title and content, why not just try:

    add_action( 'genesis_before_entry_content', 'ismh_workshops_acf' );
    function ismh_workshops_acf() {
        the_field('workshop_intro');
        the_field('registration_details');
    }

    What do you know, genesis_before_entry_content worked like a charm, but something tells me this is waaay too easy and there are ramifications which I am not aware of...? Do you see possible issues with this?

    Agreed about adding the code to my functions file rather than a template. My php coding is barely at novice stage so I wanted to get the basics right before I moved this over the functions.php and all the conditional coding this will require (using it for a cpt). These forums and sites like yours have been worth their weight in gold and it's all starting to sink in.

    September 19, 2013 at 2:30 pm #63440
    Brad Dalton
    Participant

    I just wrote a post on it which uses the before sidebar hook which you can easily change.


    Tutorials for StudioPress Themes & WooCommerce.

    September 19, 2013 at 2:56 pm #63445
    Brad Dalton
    Participant

    You could also add a conditional tag for the CPT after the function in the code:

    if ( 'workshops' == get_post_type() )
    

    Tutorials for StudioPress Themes & WooCommerce.

    September 19, 2013 at 4:45 pm #63460
    lucaslem
    Member

    That post you wrote about the before sidebar hook is exactly what led me to try the same logic with the content-entry.

    The conditional tag worked a treat 🙂

    Two of these fields will have dates and a register button inside a styled div. If that workshop is not currently scheduled then obviously those fields will be empty and the page is left with an empty styled box. If I take this a step further, is it possible to set a condition to avoid displaying the div if the editor leaves those custom fields blank?

    My current code looks like this:

    add_action( 'genesis_before_entry_content', 'ismh_workshops_acf' );
    function ismh_workshops_acf() {
        if ( 'workshops' == get_post_type() )
        echo
        '<p class="workshop_intro">' . genesis_get_custom_field('workshop_intro') . '</p>
        <div class="registration-cta">
            <p class="workshop_date">' . genesis_get_custom_field('workshop_date') . '</p>
            <a class="button" href="' . genesis_get_custom_field('registration_link') . '">Register Now!</a>
        </div>';
    }
    September 19, 2013 at 4:59 pm #63462
    lucaslem
    Member

    Oh actually, looks like I need to take a different approach. In addition to the option of not being currently scheduled, each workshop may need to display more than one date and registration button at a time, therefore the need for the call-to-action div to repeat.

    Hmmm, perhaps I should look up a tutorial for shortcodes. Then I could put all the registration details and div styling the div inside a shortcode and simply have them insert that in the custom field. If they have more than one event planned they can simply insert two shortcode lines in the custom field.

    I have a screenshots which may make this more clear:
    One registration link
    Two registration links

    September 20, 2013 at 4:43 am #63497
    Brad Dalton
    Participant

    You can use a plugin like Gravity forms for this.


    Tutorials for StudioPress Themes & WooCommerce.

    September 20, 2013 at 7:46 am #63516
    lucaslem
    Member

    Hmmm, never thought a form plugin could be used in this way. Do you mean as a replacement for ACF or as a compliment? Will go through the GF documentation and do a google search to see if I can find some leads. Thanks!

    September 20, 2013 at 8:03 am #63517
    lucaslem
    Member

    Just for clarification: the registration process happens externally (via eventbrite), so I don't need to build a registration form.

    September 20, 2013 at 8:23 am #63522
    Brad Dalton
    Participant

    Ok didn't know that.


    Tutorials for StudioPress Themes & WooCommerce.

    September 20, 2013 at 1:18 pm #63566
    lucaslem
    Member

    I've come up with another idea for this. I think repeater fields addon with AFC will allow the creation multiple call-to-action divs with same class. The only thing left is to have those divs render only when the custom fields within it are populated by the site editor. Seeing how this has largely strayed from original post, I have started a separate thread for this. Thanks.

  • Author
    Posts
Viewing 12 posts - 1 through 12 (of 12 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble