Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-07-14
4
Medium Priority
?
626 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 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
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…
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.
Suggested Courses

618 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