Adding Multiple Custom Fields to Posts

Community Forums Forums General Discussion Adding Multiple Custom Fields to Posts

This topic is: resolved

This topic contains 15 replies, has 4 voices, and was last updated by  braddalton 1 year ago.

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #44354

    slydawgg
    Participant
    Post count: 20

    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
    phone

    I 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?

    #44368

    braddalton
    Participant
    Post count: 9413

    Published 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


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

    #44375

    slydawgg
    Participant
    Post count: 20

    Thanks 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.

    #44387

    braddalton
    Participant
    Post count: 9413

    You 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.


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

    #44407

    jon0102
    Participant
    Post count: 5

    I 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.

    #44416

    braddalton
    Participant
    Post count: 9413

    Depends 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.


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

    #44420

    jon0102
    Participant
    Post count: 5

    That’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!

    #44464

    braddalton
    Participant
    Post count: 9413

    Understand 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:
    [php]
    ?><img src="<?php the_field(‘second_image’); ?>" alt="" /><?php
    endif;
    [/php]

    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.


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

    #44484

    jon0102
    Participant
    Post count: 5

    ACF 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 :(

    #44487

    braddalton
    Participant
    Post count: 9413

    The 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.


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

    #44586

    jon0102
    Participant
    Post count: 5

    I’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?

    #44591

    braddalton
    Participant
    Post count: 9413
    #44592

    Zach Russell
    Participant
    Post count: 42

    Try the book Professional WordPress Design and Development by Brad Williams! It’s a cornerstone read for any WP Developer :)


    ———-
    Zach Russell
    President, ProTech Internet Group

    #44602

    jon0102
    Participant
    Post count: 5

    Brilliant. Thanks guys! :)

    #59141

    slydawgg
    Participant
    Post count: 20

    I 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>';
    } 
    • This reply was modified 1 year ago by  slydawgg.
    • This reply was modified 1 year ago by  slydawgg.
Viewing 15 posts - 1 through 15 (of 16 total)

The topic ‘Adding Multiple Custom Fields to Posts’ is closed to new replies.