Solved

How to show post meta data in category.php ? - Wordpress

Posted on 2009-07-14
4
594 Views
Last Modified: 2012-05-07
Hello,

I'm wondering if anyone can show me how to call post metadata (from custom fields) on a category page. I know meta('field-name') used on a post page will return the value for key "field-name" but how do I use that (or another similar function like it) on a category page.

Basicly, I want to do something like this:
http://www.animefruit.com/watch/gintama/

They have the Post title ("Episodes") in one column and the post's custom field value ("Episode Title") in the one next to it.

--

The way I think about doing this would be to find a function that creates an array with all the post id's in a category.
$post_id_array = *get_post_ids_from_category*($current_category);

From there, feed that array into a foreach loop like this:

foreach ($post_id_array as $post_id) {
$episode_title_array[$post_id] = get_post_meta($post_id, $mykey);
}

After that you have to values and all that is left is to form the table

echo '<table>';
foreach ($post_id_array as $post_id) {
echo '<tr><td>';
echo '<a href="'.*post_url*($post_id).'" >'.*post_title*($post_id).'</a>';
echo '</td><td>';
echo '$episode_title_array[$post_id]';
echo '</td></tr>';
}
echo '</table>';

--
--

Note: In all code above, anything like *this* is made up/not an actual function.
0
Comment
Question by:musicmasteria
  • 2
4 Comments
 
LVL 14

Expert Comment

by:flob9
ID: 24847268
try this :

http://wordpress.org/extend/plugins/list-category-posts/

in list_cat_posts.php :

$catposts=get_posts($category.'&numberposts='.$atts['numberposts'].'&orderby='.$atts['orderby'].'&order='.$atts['order']);

etc ...
0
 
LVL 12

Accepted Solution

by:
Tony van Schaik earned 500 total points
ID: 24851364
You can try to make use of http://codex.wordpress.org/Category_Templates Category templates or Conditional tags http://codex.wordpress.org/Conditional_Tags and you can get the meta data like explained here: http://codex.wordpress.org/Using_Custom_Fields you can add those to the WP loop.
I'm using the custom fields with a category.php for my website here: www.bmwvideopost.com for a different display of the posts and category. Check below for a snippet on how i used the custom fields and posts.

<!-- CONTENT -->
<div id="content">
  <?php if (have_posts()) : ?>
  <?php while (have_posts()) : the_post(); ?>
  <div class="item" onmouseover="this.className='item2'" onmouseout="this.className='item'">
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
      <?php the_title(); ?>
      </a></h2>
    <p><a class="ceebox snap_noshots" href="<?php $values = get_post_custom_values("url"); echo $values[0]; ?>" title="<?php the_title(); ?>" target="_blank"> <img class="video-thumb" src="<?php $values = get_post_custom_values("thumbs"); echo $values[0]; ?>" alt="<?php the_title(); ?>" /></a></p>
    <div class="comment-bottom"> Posted in
      <?php the_category(', ') ?>
      | <a title="<?php comments_number('no comments','1 comment','% comments'); ?>" href="<?php the_permalink() ?>">
      <?php comments_number('no comments','1 comment','% comments'); ?>
      </a></div>
    <?php if( function_exists('ADDTOANY_SHARE_SAVE_BUTTON') ) { ADDTOANY_SHARE_SAVE_BUTTON(); } ?>
    <div class="clear"></div>
    <?php if(function_exists('the_ratings')) { the_ratings(); } ?>
  </div>
  <!-- Item Div -->
  <?php endwhile; ?>
  <div class="clear"></div>
  <?php endif; ?>
</div>
<!-- /CONTENT -->

Open in new window

0
 
LVL 3

Author Closing Comment

by:musicmasteria
ID: 31603170
Thanks for the help!
0
 
LVL 12

Expert Comment

by:Tony van Schaik
ID: 24890064
You're welcome
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
This article will show, step by step, how to integrate R code into a R Sweave document
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question