Community Forums › Forums › Archived Forums › Design Tips and Tricks › Displaying custom fields above the content
Tagged: Custom fields, Custom Post Type
- This topic has 11 replies, 2 voices, and was last updated 11 years, 3 months ago by lucaslem.
-
AuthorPosts
-
September 18, 2013 at 4:32 pm #63296lucaslemMember
Hi all,
I have created a custom post type called workshops which has :
- a title (genesis_entry_header)
- an intro block (custom field)
- registration details (custom field)
- 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 #63299Brad DaltonParticipantYou 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.
September 19, 2013 at 2:09 pm #63431lucaslemMemberHi 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 #63440Brad DaltonParticipantI just wrote a post on it which uses the before sidebar hook which you can easily change.
September 19, 2013 at 2:56 pm #63445Brad DaltonParticipantYou could also add a conditional tag for the CPT after the function in the code:
if ( 'workshops' == get_post_type() )
September 19, 2013 at 4:45 pm #63460lucaslemMemberThat 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 #63462lucaslemMemberOh 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 linksSeptember 20, 2013 at 4:43 am #63497Brad DaltonParticipantSeptember 20, 2013 at 7:46 am #63516lucaslemMemberHmmm, 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 #63517lucaslemMemberJust 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 #63522Brad DaltonParticipantSeptember 20, 2013 at 1:18 pm #63566lucaslemMemberI'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.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.