请注意如果以下代码如果无法运行,请替换代码中所有单引号和双引号为英文状态下的单引号和双引号,因为在文章中发布代码有时候单引号和双引号会被替换为中文状态下的单双引号。

    1,不需要自定义分页的情况:

    <?php $cat = get_query_var('cat'); ?>
    <ul id="pro-list-in">
    <?php while ( have_posts() ) : the_post(); ?>
    <li>
    
    </li>
    <?php endwhile;?>
    <div class="clear"></div>
    </ul>

     

    2,需要自定义分页的情况:

    <?php $term = get_queried_object()->slug; ?>
    <ul class="pro-list-in">
    
    <?php
    $page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
    $search_args = array(
    'post_type' => 'portfolio',
    'posts_per_page' => '6',
    'paged' =>  $page,
    'tax_query' => array(
    array(
    'taxonomy' => 'portfolio_category',
    'field' => 'slug',
    'terms' => $term )
    )
    );
    $i=1;
    query_posts($search_args);?>
    <?php while ( have_posts() ) : the_post(); ?>
    <li>
    </li>
    <?php endwhile;?>
    <div class="pagination fixed">
    <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
    </div><!-- end .pagination -->
    <?php wp_reset_query();  ?>
    
    </ul>

     

    3,通用调用方式:

    <?php $term = get_queried_object()->slug; ?>
    
    <ul class="pro-list-in">
    <?php
    $page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
    $search_args = array(
    'post_type' => 'portfolio',
    'posts_per_page' => '21',
    'paged' =>  $page,
    'tax_query' => array(
    array(
    'taxonomy' => 'portfolio-category',
    'field' => 'slug',
    'terms' => $term )
    )
    );
    query_posts($search_args);
    ?>
    <?php //query_posts("posts_per_page=10&post_type=post"); ?>
    <?php while ( have_posts() ) : the_post(); ?>
    <li>
    <?php $thumb_t = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large' ); $url_t = $thumb_t['0']; ?>
    <?php if ($thumb_t) : ?>
    <div class="slider-img">
    <a href="<?php echo get_permalink($post->ID) ?>" class="thumbnail" title="<?php echo $post->post_title ?>"><img src="<?php bloginfo('template_url')?>/timthumb.php?src=<?php echo $url_t ?>&amp;w=170&amp;h=170;&amp;zc=1" width="170" height="170"></a>
    </div>
    <?php else :?>
    <div class="slider-img">
    <a href="<?php echo get_permalink($post->ID) ?>" class="thumbnail" title="<?php echo $post->post_title ?>"><img src="<?php bloginfo('template_url')?>/timthumb.php?src=/images/default.png&amp;w=170&amp;h=170;&amp;zc=1" width="170" height="170"></a>
    </div>
    <?php endif; ?>
    <?php //the_excerpt(); ?>
    <div class="title"><a href="<?php echo get_permalink($post->ID) ?>" title="<?php echo $post->post_title ?>"><?php the_title(); ?></a></div>
    </li>
    <?php endwhile;?>
    <div class="clear"></div>
    <div class="pagination gdl-divider"><?php echo pagination(); ?></div>
    <?php wp_reset_query();  ?>
    </ul>

     

    4,调用自定义字段通用代码

    <?php
    $term = get_queried_object();
    $tax = 'product_cat';
    $term_id = $term->term_id;
    ?>
    <a href="<?php the_field('banner_href', 'product_cat_'.$term_id) ?>" class="banner-href" title="links"></a>
    <?php $banner_img = get_field('banner_img', 'product_cat_'.$term_id);?>
    <img src="<?php bloginfo('template_url')?>/timthumb.php?src=<?php echo $banner_img ?>&amp;w=1920&amp;h=200;&amp;zc=1" alt="<?php echo $category->name ?>" width="100%" height="700">