Get help. Give help. A Web Design and Development Community.

styling metaData

  • # April 17, 2013 at 11:14 am

    Hey guys. I’m trying to style the metaData from a wordpress post. I need to make a for loop that goes through all the meta data (if there is some) and style it as follows



    # April 17, 2013 at 11:22 am

    So what is your question?

    How to style it…or how to achieve the loop?

    # April 17, 2013 at 11:32 am

    How to achieve the loop and style it?

    # April 17, 2013 at 11:34 am

    get post meta is your friend

    simple use
    < ?php $meta_values = get_post_meta($post_id, $key, $single); ?>

    and then you get each field from its name saved

    you can read how to set the meta boxes here

    # April 17, 2013 at 11:38 am

    I’m not exactly sure to how write the for loop and add in my styling divs for the name a value. Could someone help me do that?

    # April 17, 2013 at 11:57 am

    < ?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    < ?php echo get_post_meta(get_the_ID(), 'custom_field_1_name', true); ?>

    < ?php echo get_post_meta(get_the_ID(), 'custom_field_1_name', true); ?>

    < ?php endwhile; ?>

    < ?php else: ?>

    < ?php endif; ?>

    the code will work for as many post as you have queried and have these meta keys

    # April 17, 2013 at 11:58 am

    Awesome. Thank you very much for the help on this. It’s a keeper for sure.

    # April 17, 2013 at 12:25 pm

    That didn’t quite work out. It went haywire and listed the post hundreds and hundreds of times.

    I want to take each custom field entry and style it.

    customfield NAME goes in div class=”detailTitle”>NAME /div
    customfield VALUE goes in div class=”detailValue”>VALUE /div

    for each custom item on this project/post do…..
    div class=”projectDetails”
    div class=”detailTitle”>NAME /div
    div class=”detailValue”>VALUE /div

    This forloop is going on my Single.php

    # April 17, 2013 at 12:27 pm

    what plugin are you using to add the custom fields?

    # April 17, 2013 at 12:28 pm

    Nothing. I using the standard one that comes with wp

    # April 17, 2013 at 12:29 pm

    also to the bottom there is a link saying use them in your theme. did you mind pressing it? im sure it has instructions how to do it

    # April 17, 2013 at 12:33 pm

    in my code you have to replace the ‘custom_field_1_name’ with ‘Authors’ and the second line to ‘Studio’ did you do that?

    # April 17, 2013 at 12:53 pm

    alright ill check that out.
    Thank you

    # April 17, 2013 at 12:54 pm

    No I didn’t do that. I wanted it to automatically just continue going through however many custom fields there were.

    # April 17, 2013 at 1:01 pm

    < ?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    < ?php $meta = get_post_meta( get_the_ID() );
    foreach ($meta as $key => $value){ ?>

    < ?php echo $key; ?>

    < ?php echo $value; ?>

    < ?php } ?>
    < ?php endwhile; ?>

    < ?php else: ?>

    < ?php endif; ?>

    try this one

Viewing 15 posts - 1 through 15 (of 16 total)

You must be logged in to reply to this topic.

We have a pretty good* newsletter.