Displaying custom fields above the content

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

This topic is: resolved

This topic contains 11 replies, has 2 voices, and was last updated by  lucaslem 10 months, 1 week ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #63296

    lucaslem
    Participant
    Post count: 88

    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.

    • This topic was modified 10 months, 2 weeks ago by  lucaslem.
    • This topic was modified 10 months, 2 weeks ago by  lucaslem.
    #63299

    braddalton
    Participant
    Post count: 8873

    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.
    [php]
    add_action( ‘genesis_entry_header’, ‘ismh_workshops_acf’ );
    [/php]

    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.


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

    #63431

    lucaslem
    Participant
    Post count: 88

    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.

    #63440

    braddalton
    Participant
    Post count: 8873

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


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

    #63445

    braddalton
    Participant
    Post count: 8873

    You could also add a conditional tag for the CPT after the function in the code:
    [php]
    if ( ‘workshops’ == get_post_type() )
    [/php]


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

    #63460

    lucaslem
    Participant
    Post count: 88

    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>';
    }
    #63462

    lucaslem
    Participant
    Post count: 88

    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

    #63497

    braddalton
    Participant
    Post count: 8873

    You can use a plugin like Gravity forms for this.


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

    #63516

    lucaslem
    Participant
    Post count: 88

    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!

    #63517

    lucaslem
    Participant
    Post count: 88

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

    #63522

    braddalton
    Participant
    Post count: 8873

    Ok didn’t know that.


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

    #63566

    lucaslem
    Participant
    Post count: 88

    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.

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.