0

I am have a theme by the "blog" post type and I use the code below to add term category to this post type

$labels = array(
        'name'                                            => 'دسته‌ها',
        'singular_name'                          => 'دسته‌ها',
        'search_items'                            => 'جستجوی دسته',
        'popular_items'                          => 'بیشتر استفاده شده',
        'all_items'                                      => 'تمام دسته‌ها',
        'parent_item'                              => 'مادر دسته',
        'edit_item'                                      => 'ویرایش دسته',
        'update_item'                              => 'بروزرسانی دسته',
        'add_new_item'                            => 'افزودن دسته جدید',
        'new_item_name'                          => 'دسته جدید',
        'separate_items_with_commas'    => 'جداسازی دسته‌ها با کاما',
        'add_or_remove_items'              => 'افزودن یا حذف دسته',
        'choose_from_most_used'          => 'انتخاب از محبوبها'
        );
$args = array(
  'label'                                                => 'دسته‌',
  'labels'                                              => $labels,
  'public'                                              => true,
  'hierarchical'                                  => true,
  'show_ui'                                        => true,
  'show_in_nav_menus'                    => true,
  'args'                                                  => array( 'orderby' => 'term_order' ),
  'rewrite'                                        => array( 'slug' => 'term', 'with_front' => true ),
  'query_var'                                    => true
);
register_taxonomy( 'term', 'blog', $args );

I don't know what query can see the posts and I need to know how to add pagination to this file.

My taxonomy-term.php:

<?php get_header(''); ?>
<section id="description">
  <div class="container">
    <hgroup>
    <h1>وبلاگ روکش</h1>
    <h2>
    <P> آخرین اخبار و رویداد های روکش را در وبلاگ روکش دنبال کنید و از تکنولوژی ها و آموزش های روکش در حهت افزایش آگاهی و مهارت های خود در زمینه طراحی وب استفاده کنید. </P>
    </h3>
    </hgroup>
  </div>
</section>
<?php if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb('<div class="breadcrumbs"><div class="container">','</div></div>');
} ?>
<div id="blog">
<div class="container">
<section id="main-blog">
<div class="post-items">
<?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query();
if(!empty($wp->query_vars['term'])){ $terms = $wp->query_vars['term']; $taxonomy = 'term'; }
if(!empty($wp->query_vars['library-tags'])){ $terms = $wp->query_vars['library-tags']; $taxonomy = 'library-tags'; }
$paged = ($wp->query_vars['page']) ? $wp->query_vars['page'] : 1;
$args = array(
  'post_type' => 'blog',
  'paged' => $paged,
  'tax_query' => array(
   array(
                'taxonomy' => $taxonomy,
                'field' => 'slug',
                'terms' => $terms
   )
  )
);
$wp_query->query( $args ); ?>
<?php if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

    <div class="news" id="<?php the_ID();?>">
            <header>
            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
            <figure>
                <img alt="<?php the_title(); ?>" title="<?php the_title(); ?>" src="" />
            </figure>
            </a>
            <span class="cat">
                <?php echo get_the_term_list( $post->ID, 'term',  ' ', '' ); ?> 
            </span>
            <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
            <div class="detail">
                <span class="author">
                    <i class="icon-user"></i>
                    <?php the_author_posts_link();?>
                </span>
                <span class="date">
                    <i class="icon-calendar-empty"></i>
                    <?php the_date('d F y') ;?>
                </span>
            <div class="clear"></div>
            </div>
        </header>
        <article>
            <?php the_content("ادامه مطلب ..."); ?>
        </article>
    </div>

<?PHP endwhile; endif; ?>
<?php paginate(); ?>
<?php $wp_query = null; $wp_query = $temp;?>

</section>
<aside id="sidbar-blog">
    <div>
        <h3>خبرنامه روکش</h3>
        <form>
            <input type="text" placeholder="ایمیل خود را وارد کنید"/>
            <input type="submit" value="ثبت"/>
        </form>
        <div class="clear"></div>
    </div>
    <nav>
    <h3>دسته بندی ها</h3>
        <?php
        $args = array('container' => false, 'theme_location' => 'blog');
        wp_nav_menu($args);
?><div class="clear"></div>
    </nav>
</aside>
<div class="clear"></div>
</div>
</div>
            <?php get_footer(); ?>
            <?php wp_footer(); ?>
3
  • 2
    Can I suggest not naming your taxonomy term? Even so: what does your taxonomy-term.php file look like? Commented Oct 11, 2013 at 13:07
  • why? "Can I suggest not naming your taxonomy term?" i'am add taxonomy-term.php to my question Commented Oct 11, 2013 at 13:40
  • 1
    Why are you outputting a custom query loop in taxonomy-term.php? Where is the default loop? Commented Oct 11, 2013 at 13:49

1 Answer 1

0

The problem is that you're not letting the template file do what it is intended to do. Instead of outputting the default loop, you're ignoring the default loop, and outputting a custom query loop.

Replace all this:

<?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query();
if(!empty($wp->query_vars['term'])){ $terms = $wp->query_vars['term']; $taxonomy = 'term'; }
if(!empty($wp->query_vars['library-tags'])){ $terms = $wp->query_vars['library-tags']; $taxonomy = 'library-tags'; }
$paged = ($wp->query_vars['page']) ? $wp->query_vars['page'] : 1;
$args = array(
  'post_type' => 'blog',
  'paged' => $paged,
  'tax_query' => array(
   array(
                'taxonomy' => $taxonomy,
                'field' => 'slug',
                'terms' => $terms
   )
  )
);
$wp_query->query( $args ); ?>
<?php if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

with the default loop markup:

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

Then, your taxonomy-term.php template file will work properly, including pagination.

6
  • i do this but i cant see any post. see this link Commented Oct 11, 2013 at 14:33
  • What is returned in the $wp_query object? What is the name of your taxonomy? Your URL says the term is wp-ttus. Your original template code seems to query the term library-tags. Commented Oct 11, 2013 at 14:40
  • rokesh.ir/term/wp-ttus >> "term" it's the slug and "wp-ttus" it's a category of this slug. its another category Commented Oct 11, 2013 at 15:03
  • It would be helpful (and less confusing) if you use the proper terms. I'm not sure if "category" (which is a core-registered taxonomy) has anything to do with the issue. Is it correct that term is the taxonomy slug, and wp-ttus is the slug of a term for the term taxonomy? Commented Oct 11, 2013 at 15:19

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