Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have created a custom post type "Portfolio" and a custom taxonomy "Kind" which includes "Websites", "Graphics", "Programming".

What I want to do is to create 3 different pages "Websites", "Graphics" etc. that will display the appropriate items as a list.

This is my code to display "Portfolio" posts :

<?php query_posts( array( 'post_type' => 'portfolio') ); ?>
    <?php if( is_tax() ) {
        global $wp_query;
        $term = $wp_query->get_queried_object();
        $title = $term->name;
    }  ?>

            <div id="content" class="clearfix">
                <div id="main" class="clearfix" role="main">
                    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                    <?php $categories = get_the_category(); ?>
                    <article id="post-<?php the_ID(); ?>" <?php post_class('clearfix single-post'); ?> role="article" itemscope itemtype="http://schema.org/BlogPosting">
                        <header>
                            <?php the_post_thumbnail( 'wpbs-featured' ); ?>
                            <div class="page-header"><h3 itemprop="headline"><?php the_title(); ?></h3></div>
                        </header> <!-- end article header -->

                        <section class="post_content clearfix">
                            <?php the_content(); ?>
                        </section>

                        <!--<footer>
                            </footer>--> <!-- end article footer -->

                    </article> <!-- end article -->

                    <?php endwhile; ?>          
                    <?php else : ?>
                    <?php endif; ?>

                </div> <!-- end #main -->    
            </div> <!-- end #content -->

Unfortunately, I can't manage to display only "graphics" or "websites" posts.

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

Create taxonomy archives, not pages.

Create three separate files called

taxonomy-kind-websites.php
taxonomy-kind-graphics.php
taxonomy-kind-programming.php

Displaying the items/posts as a list is pretty simple, eg

<ul class="my-posts">       
 <?php while ( have_posts() ) : the_post(); ?>
  <li><h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
  </li>
 <?php endwhile; ?>
</ul>

You may also need to add the following to your arguments

'rewrite' => array( 'slug' => 'kind')

when you register your taxonomy

Update: Have a look at http://kovshenin.com/2012/how-to-add-taxonomies-to-your-custom-post-types-in-wordpress/ on how to add custom taxonomies to custom post types. I would, however, not create a new post type but instead a category called "Portfolio" and then create a single post template for this category, called single-portfolio.php, where you can customize the design easily. You can then further customize by replacing the call <?php get_template_part( 'content', 'single' ); ?> with your own <?php get_template_part( 'custom', 'single' ); ?>.

share|improve this answer
    
and how do I display only "websites" from taxonomy "Kind" ? –  RobDel Jun 11 '13 at 10:28
    
Include the loop above inside taxonomy-kind-websites.php and then simply visit the taxonomy term archive and the posts with the term 'website' selected will display. You will find the url by clicking "view" under Posts > Kind > Websites in the admin area. –  psot Jun 11 '13 at 10:48
    
Do you mean that wordpress picks up the name of taxonomy from the filename automatically ? In case of "taxonomy-kind-website.php" wordpress sees "website" ? –  RobDel Jun 11 '13 at 11:00
    
Sorry I just deleted a comment. The terms aren't registered but created from the admin area of course. Make sure the term name is 'websites' if the file is taxonomy-kind-websites.php –  psot Jun 11 '13 at 11:02
    
Yes, excactly, Wordpress gets the posts belonging to the "website" term if you have created the template taxonomy-kind-website.php. –  psot Jun 11 '13 at 11:05
show 7 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.