Solved

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

Posted on 2009-07-14
4
609 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

688 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