Community Forums › Forums › Archived Forums › General Discussion › question about showing custom fields
Tagged: custom fileds
- This topic has 3 replies, 2 voices, and was last updated 10 years, 7 months ago by Brad Dalton.
-
AuthorPosts
-
September 22, 2013 at 8:10 pm #63806KevinMember
I've been asking questions about this and I am slowly getting to where I need to be. I am developing a site for a school where I work (It's currently not accessible until I finish it). I created CPT for teachers, who work in clusters (e.g. Cluster 1 :: Grade 6, Cluster 2 :: Grade 6 and so on), to enter daily homework. Each time they create a post, there are custom fields for them to fill in by subject (math, ELA, science, social studies). When a parent/ students clicks on the cluster link, it takes them to a page that shows just the titles of each post and links to the single page for that post. I created a page template for each cluster. I also added
genesis_get_custom_field
for each custom field so it shows on the single.php page. For example, `add_action('genesis_post_content', 'science');
function science() {
if ( is_single() && genesis_get_custom_field('science') )
echo '<h2>Science</h2>';
echo '<div id="homework-content">'. genesis_get_custom_field('science') .'</div>';
}
add_action('genesis_post_content', 'social_studies');
function social_studies() {
if ( is_single() && genesis_get_custom_field('social_studies') )
echo '<h2>Social Studies</h2>';
echo '<div id="homework-content">'. genesis_get_custom_field('social_studies') .'</div>'`
This all works great except that the add_function for the custom fields shows under each post/ page content. I see it because I added background in the css.
So, to get to my question, is there a way to use the genesis_get_custom_field so it just shows on the CPT pages? I tried an if statement to no avail.
Thanks for any help and sorry it's so long.September 23, 2013 at 5:50 am #63832Brad DaltonParticipantInstall the ACF plugin. Here's a screenshot of what options you get and how you can determine exactly where the CF displays in the backend. http://wpsites.net/web-design/add-custom-field-before-sidebar-on-any-post/#Step_2
Simply use exactly the same field name in your code as you use in the plugin settings and it hooks in your code to the plugin so you can create met boxes and use the conditional logic to display them according to your needs.
September 24, 2013 at 11:36 am #63988KevinMemberI haven't tried this yet but what I want is the actual content (not above sidebar) of the page to be displayed through the custom fields. So the process would be click on a post link->takes you to the custom template that displays just the custom fields. I am using the ACF plugin. Would be as simple as moving the code I posted above from the functions.php page to the custom template page?
September 24, 2013 at 12:05 pm #63994Brad DaltonParticipantNot sure as i would need to test it all locally and find the best solution by trying different methods.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.