0

I am creating wordpress template that can use custom taxonomy(like categories). i want that every time i click the post's category it shows the list of post of that category. here is my category.php.

<?php get_header(); ?>
<body>
<div id="container">
    <div id="header"><h1><a href="<?php echo get_option('home'); ?>"><?php bloginfo('name'); ?></a></h1></div>
    <div id="menu"><?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'menu_class' => 'nav', 'theme_location' => 'primary-menu' ) ); ?></div>
    <div id="content">
        <div id="blog">
        <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
            <?php /* If this is a category archive */ if (is_category()) { ?>
                <h2>Archive for the &#8216;<?php single_cat_title(); ?>&#8217; Category:</h2>
            <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
                <h2>Posts Tagged &#8216;<?php single_tag_title(); ?>&#8217;</h2>
            <?php /* If this is a daily archive */ } elseif (is_day()) { ?>
                <h2>Archive for <?php the_time('F jS, Y'); ?>:</h2>
            <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
                <h2>Archive for <?php the_time('F, Y'); ?>:</h2>
            <?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
                <h2>Archive for <?php the_time('Y'); ?>:</h2>
            <?php /* If this is an author archive */ } elseif (is_author()) { ?>
                <h2>Author Archive</h2>
            <?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
                <h2>Blog Archives</h2>
        <?php } ?>

        <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>

        <div class="post">
        <br>
        <br>
        <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>

            <div class="entry">
            <br>    
                <?php the_content(); ?>

                <p class="postmetadata">
                <?php _e('Filed under&#58;'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php  the_author(); ?><br />
                <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit', ' &#124; ', ''); ?>
                </p>

            </div>
            <br>
            <hr>
            <br>
        </div>

        <?php endwhile; ?>

        <div class="navigation">
        <?php posts_nav_link(); ?>
        </div>

        <?php endif; ?>
    </div>
    </div>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

I already searching whole day and nothing working. what custom taxonomy template archive name i should use ? what code that i must change in this category.php to fulfill the needs of displaying the custom taxonomy archives(that can display all post that related to the clicked taxonomy) ?

2 Answers2

1

You should create a taxonomy.php for terms belonging to a custom taxonomy. You can just simply copy the template above and call it taxonomy.php

EDIT

You have one big fundamental flaw when registering your two taxonomies.

You cannot have white spaces in your custom taxonomy names, and this applies to function names and custom post type names as well. The following rules apply, and there is no work around these.

  • names cannot contain white spaces or any special character.

  • only lowercase letters are allowed

  • if a name contains more that one word, you can only use underscores (_) to separate them. Do not use hyphens (-) as you will have issues later on

  • see the codex for the limitation on character count for taxonomies and post types

So, in short, kategori berita and tag berita is invalid names. They should be kategori_berita and tag_berita. As I said, there are no work around to this problem. Your only solutions is to change your taxonomy names accordingly

Pieter Goosen
  • 9,768
  • 5
  • 35
  • 55
  • 1
    Did you set `public` to `true` when you register your taxonomy? Also, did you flush your permalinks? – Pieter Goosen Oct 01 '14 at 09:47
  • yes i have set the public property to true, i have flush the permalinks too but nothings changed. here is my code to register the taxonomy : jsfiddle.net/bkrs2bvk – I Putu Saputra Oct 02 '14 at 03:37
1

When the name of your taxonomy is "roles", you could create a file called taxonomy-roles.php. You can expand this with the term (in this example "ceo") like this as well: taxonomy-roles-ceo.php.

As @pietergoosen said you can just copy paste the code that you provided with in those files.

For more info on this you can check out the following link: http://codex.wordpress.org/Template_Hierarchy#Custom_Taxonomies_display

Gerben van Dijk
  • 868
  • 6
  • 15
  • 1
    +1. Your answer is more comprehensive than mine. Did mine on the fly this morning before leaving home :-) – Pieter Goosen Oct 01 '14 at 07:26
  • it still not working. it shows page not found. my taxonomy name is Kategori Berita so i created taxonomy-Kategori Berita.php as the custom taxonomy template. – I Putu Saputra Oct 01 '14 at 09:32
  • @IPutuSaputra - would you mind sharing the code that creates the taxonomy? At the moment, you are using the label of the taxonomy in your taxonomy-*.php file. This should not be the name, but the identifier of the taxonomy (could be something like kategori-berita in your case - but this depends on how you've registered the taxonomy. If you share your code then I'll let you know what the name of your taxonomy-*.php file should be. – Gerben van Dijk Oct 01 '14 at 09:38