Solved

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

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

738 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