Get page content by category or tag

It sounds like you really need to be using posts for your content rather than pages since you want to organize your content into categories. You can use a page to display a custom page template (the Template Name: comment as shown below defines a new page template; that template will then be available as a in a dropdown near the page “publish” button). This template can show metadata from posts in a particular category by using code similar to this:

<?php
 /*
Template Name: My Page Template
*/
?>
<?php get_header(); ?>

<h3>My Posts in My Category</h3>

   <?php 
   query_posts('category_name=my-category-slug-name&showposts=3'); ?>

   while (have_posts()) : the_post(); 
      thumb = get_post_meta($post->ID, "promo_image-215x150", true);

      if ($thumb != "")  { ?> 
        <a href="https://wordpress.stackexchange.com/questions/59809/<?php the_permalink() ?>" title="<?php the_title(); ?>">
          <img src="<?php $values = get_post_custom_values("promo_image");
          echo $values[0]; ?>" alt="<?php the_title(); ?>"  />
        </a>

     <?php 
     } else { ?>
       <a href="https://wordpress.stackexchange.com/questions/59809/<?php the_permalink() ?>" rel="bookmark"><?php the_title (); ?></a>
     <?php } ?>

  <?php endwhile; ?>

Leave a Comment