Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using WordPress 3.5.1 / Twenty Twelve theme. I am using custom fields and displaying them in category.php in the following way, the php is setup inside category.php in the "/* Start the Loop */ "

$metastime = get_post_meta($post->ID,'user_submit_starttime',true);
echo '<a class="metastime">'.$metastime.'</a>';
$metaetime = get_post_meta($post->ID,'user_submit_endtime',true);
echo '<a class="metaetime">'.$metaetime.'</a>';
$metaloc = get_post_meta($post->ID,'user_submit_location',true);
echo '<a class="metaloc">'.$metaloc.'</a>';

It works as the custom fields are displaying when I view the category archives (the custom fields are displayed under each post title), but I assume there is a better function to use. Like the the following?

get_template_part( 'content', get_post_format() );

Since that code is specific to content.php, I would like the custom fields to show up where the

<div class="entry-content"> <?php the_content('Read more...'); ?> </div>

Resides in content.php, What is the best way to display the custom fields so they display were the "entry-content" is displayed in category.php ?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

You might try the the_content filter with the conditional tag is_category() to append a string to the post content when viewing the category archives :

add_filter( 'the_content', 'custom_the_content' );
function custom_the_content( $content ){
    if( is_category() ):
        $metastime = get_post_meta( get_the_ID(), 'user_submit_starttime', true );
        $metaetime = get_post_meta( get_the_ID(), 'user_submit_endtime'  , true );
        $metaloc   = get_post_meta( get_the_ID(), 'user_submit_location' , true );
        $content  .= '<a class="metastime">' . $metastime . '</a>';
        $content  .= '<a class="metaetime">' . $metaetime . '</a>';
        $content  .= '<a class="metaloc">'   . $metaloc   . '</a>';
    endif;
    return $content;
}
share|improve this answer
    
you can add this into your functions.php file in the current theme directory, or better yet create a plugin from this. –  birgire Jun 17 '13 at 19:42
    
Adding your code into functions.php did the trick, Thank you. –  Mills Jun 17 '13 at 19:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.