Solved

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

Posted on 2009-07-14
4
577 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now