Use custom fields in query posts to display one category in sidebar of a page
-
Hello,
I am using page.php and sidebar.php and I want to display 3 posts from a specific category that I can call in the custom fields using query_posts.
It would be easy to create 30+ page templates using this:
<?php query_posts('cat=23&showposts=3'); ?>
However, this is the more efficient way. I would like to use the custom fields to replace the category id somehow like this:
<?php if ( get_post_meta($post->ID, 'team-category-slug', true) ) { ?> <?php query_posts('cat=<?php echo get_post_meta( $post->ID, "team-category-slug", true ); ?>&showposts=3'); ?> <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
Any ideas to get the value to be displayed in query_post so only that specific category will be displayed?
Thanks ahead of time!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Use custom fields in query posts to display one category in sidebar of a page’ is closed to new replies.