Community Forums › Forums › Archived Forums › General Discussion › Adding Multiple Custom Fields to Posts
Tagged: Custom fields, hooks, plugins
- This topic has 15 replies, 4 voices, and was last updated 11 years ago by Brad Dalton.
-
AuthorPosts
-
June 6, 2013 at 10:49 am #44354slydawggMember
I've created multiple Custom Fields for one of my sites, but am not sure I can locate the best method for making them display on either the Category Page and/or the Single Post.
I've seen across this forum and other websites to just edit the functions.php file, but if I am not using a child-theme, wouldn't editing the functions.php file within Genesis be a really bad idea?
Some folks even say just drop your code into Simple Hooks, but I am not 100% that is what would do what I am trying to accomplish; so here is my idea...
My custom fields are:
webpage-url
phoneI would like the Posts single page to look something like:
Post Title
Post Body
Custom-field "webpage-url"
Custom-field "phone"And if possible the Category Page to be the same as above, but all Posts in the same Category
Has anybody done this successfully, or are people using plugins instead of the Genesis Framework?
June 6, 2013 at 11:47 am #44368Brad DaltonParticipantPublished 3 posts on this in the last 2 weeks.
The Advanced Custom fields plugin is excellent if you want multiple custom fields and meta boxes.
Nick has also written about this in detail.http://designsbynickthegeek.com/tutorials/how-i-make-custom-fields-easier
June 6, 2013 at 12:03 pm #44375slydawggMemberThanks for the quick reply. Unfortunately I was trying to use this plugin earlier and although I created a custom field and gave all of the "Location" information, the custom field still doesn't appear to ever display on the page itself.
I guess I will keep trying to see if there is something I have missed along the way.
June 6, 2013 at 12:31 pm #44387Brad DaltonParticipantYou have to add code to your child themes functions.php file in order for the custom field to work.
Simply creating a custom field won't work.
The plugin also enables you to create custom meta boxes in your edit screens.
June 6, 2013 at 1:45 pm #44407jon0102MemberI need some help with this as well.
I've used ACF to create the field, but I can't figure out where to put the php to get it to display on the front-end.
I created my own child theme from scratch, so there are no existing loops in my functions.php file. Would I need to create a custom loop in order to add my field? Simply adding get_field( "featured_image_description" ); or genesis_get_custom_field("featured_image_description" ); to functions.php doesn't seem to work.
June 6, 2013 at 2:21 pm #44416Brad DaltonParticipantDepends on what you want to do with the custom field.
Here's an example for images:
Code not displaying? Grab it on Github.
You'll need to check out the code examples on the ACF website.
June 6, 2013 at 2:42 pm #44420jon0102MemberThat's useful, but it's not an image. It's just text.
I want to be able to add a description to all the featured images on the site. The field would display along with all the other post data (using the Genesis Featured Page widget) and I'd overlay it, sort of like a note on the bottom of a polaroid, using CSS.
I'm just not familiar enough with php to figure it out, yet. No matter what I add or tweak in function.php myself I just can't get that darned line of text to appear on the front end!
June 6, 2013 at 7:54 pm #44464Brad DaltonParticipantUnderstand which is why i linked to the ACF code snippets.
They also offer a forum where you can get the code.
Once you have the code, the rest is simple.
You could also remove this line:
?><img src="<?php the_field('second_image'); ?>" alt="" /><?php endif;
from the code above and change the field name from second_image to your own which should be the same as you use when creating the field using the plugin.
You can also change the conditional tag and hook in the code above.
June 7, 2013 at 3:16 am #44484jon0102MemberACF seem to be having problems with their website the last couple of days. I couldn't get on the day before yesterday, could briefly yesterday and can't again today.
The code they give on their website just doesn't work as it should, because they assume you're inserting it at a specific point in your loop, which I don't have the code for in my child theme.
Would they be able to offer specific examples of how to get this to work in Genesis? Unfortunately the code above isn't doing anything 🙁
June 7, 2013 at 3:46 am #44487Brad DaltonParticipantThe code i supplied above works for images only.
You could try posting on their forum and asking for a custom function.
Another option is to use another custom fields plugin.
June 7, 2013 at 12:29 pm #44586jon0102MemberI'm not sure it's a problem with the plugin itself, but how I'm handling the php side of things. Never mind.
Thanks for all your help!
Out of curiosity, where online would you recommend for me to buff up my WordPress PHP knowledge, from very much a beginner's level?
June 7, 2013 at 12:40 pm #44591Brad DaltonParticipantI think its different for everyone.
You could try sites like:
http://devzone.zend.com/6/php-101-php-for-the-absolute-beginner/
I think videos are the best
http://www.lynda.com/PHP-training-tutorials/282-0.html
http://net.tutsplus.com/tutorials/php/learn-php-from-scratch-a-training-regimen/
June 7, 2013 at 12:41 pm #44592Zach RussellMemberTry the book Professional WordPress Design and Development by Brad Williams! It's a cornerstone read for any WP Developer 🙂
———-
Zach Russell
President, ProTech Internet GroupJune 7, 2013 at 12:51 pm #44602jon0102MemberBrilliant. Thanks guys! 🙂
August 27, 2013 at 6:40 pm #59141slydawggMemberI meant to follow up on this. I ended up using a combination of Brad's code above, and changing it to better suit my needs. Here is what I ended up using in case it helps others.
add_action('genesis_post_content', 'title'); function title() { if ( is_single() && genesis_get_custom_field('title') ) echo '<hr /><div id="postition_title">Title: '. genesis_get_custom_field('title') .'</div>'; } add_action('genesis_post_content', 'phone'); function phone() { if ( is_single() && genesis_get_custom_field('phone') ) echo '<div id="phone">Phone Number: '. '<a href="tel:' .genesis_get_custom_field('phone') . '">' . genesis_get_custom_field('phone') .'</a></div>'; }
August 27, 2013 at 6:54 pm #59144Brad DaltonParticipant -
AuthorPosts
- The topic ‘Adding Multiple Custom Fields to Posts’ is closed to new replies.