• I am setting up a portfolio. There are pages set up for each type of item (big logos, medium logos, small logos). I have set up custom post types for each type of logo, where the categories are the same as the page titles (big, medium, small). I would like to just use one template and not create a separate one for each logo type (I am trying to get out of the habit of creating a template every time I want to display posts from a certain category). So when I view Medium Logos, it just pulls in the medium logos, using a single template.

    Pardon if this is a fairly simple process, I think I just got into bad WP coding habits. Custom templates are great, but I know there is a more efficient way to do this.

    Thanks in advance.

Viewing 1 replies (of 1 total)
  • Thread Starter pantone204

    (@pantone204)

    I may have just figured it out. I used the following….

    <?php $args = array('category_name' => $post->post_name, 'post_type' => array ('portfolio-items'));
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>   		
    
            <span class="pdfp"><?php the_title(); ?></span>                
    
      <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Display list of custom posts according to page title’ is closed to new replies.