0

在投资组合页面上,我想要有限数量的产品。我有 300 种产品,这太多了,不能全部放在一页上。

我将此代码用于有限数量的产品(每页 10 个产品)

'posts_per_page' => 10

我把这段代码用于插入页面切换(在本例中为 30 页)

<!-- Pagination -->
<?php if(function_exists('pagination')){ pagination(); }else{ paginate_links(); } ?>
<!-- Pagination End -->

事实上,这两种代码都有效。显示的产品数量仅限于 10 个产品。在页面底部,我可以选择切换到 30 页之一。

但无论我点击哪个数字页面,我总是打开前 10 个产品。

投资组合页面 - PHP 代码

<?php 
/* 
Template Name: Portfolio 4 Column
*/ 
?>

<?php get_header(); ?>


<?php



    if ( function_exists( 'get_option_tree') ) {
        $tune_portfoliolock = get_option_tree( 'value_portfolio4columnlock' );
        if($tune_portfoliolock != 0 && $tune_portfoliolock != ""){ $tune_pih = $tune_portfoliolock; }else{ $tune_pih = null; }
    }

    $templateurl = get_template_directory_uri();
    $pagecustoms = getOptions();

    if (isset($pagecustoms["header_title"])){$tune_htitle = $pagecustoms['header_title'];}else{$tune_htitle = "";}
    if (isset($pagecustoms["sidebar_orientation"])){$tune_sideo = $pagecustoms['sidebar_orientation'];}else{$tune_sideo = 1;}
    if ($tune_sideo == 0){$conorient = "right"; $sideoffset = ""; $conoffset = "offset-by-one";}else{$conorient = "left"; $sideoffset = "offset-by-one"; $conoffset = "";}
    if (isset($pagecustoms["sidebar"])){$tune_sidebar = $pagecustoms["sidebar"];}else{$tune_sidebar = "Page Sidebar";}
    if (isset($pagecustoms["portfolio_category"])){
        $ptype = $pagecustoms['portfolio_category'];
        $pcat = "category_".$ptype;
    }
    if (isset($pagecustoms["portfolio_alpha"])){ if($pagecustoms['portfolio_alpha']!=""){$tune_folioalpha = $pagecustoms['portfolio_alpha'];}else{$tune_folioalpha = 0;}}else{
$tune_folioalpha = 0;}
?>

<!-- Text Block
================================================== -->

<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<?php if( get_the_content() != ""){ ?>
<div class="sixteen columns row textblock">
<?php } else { ?>
<div class="sixteen columns row textblock" style="margin-top: -26px;">
<?php } the_content(); endwhile; endif; ?><div class="clear"></div>
</div>

<?php 
$args=array(
    'post_type' => $ptype,
    'posts_per_page' => 10
);
$temp = $wp_query; 
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query($args);
$terms = get_terms($pcat);
?>

<!-- Portfolio Filters
================================================== -->

<div class="sixteen columns row noheadline"></div>

<div class="sixteen columns row portfolio_filter">
    <ul>
        <?php
        echo '<li><a class="portfolio_selector" data-group="all-group" href="#">'.__('All Projects', 'tune').'</a><span>&middot;</span></li>';
        foreach ( $terms as $term ) {
            $filter_last_item = end($terms);
            if($term!=$filter_last_item){
                echo '<li><a class="portfolio_selector" data-group="'.strtolower(str_replace(" ", "-", $term->name)).'" href="#">'.$term->name.'</a><span>&middot;</span></li>';
            }else{
                echo '<li><a class="portfolio_selector" data-group="'.strtolower(str_replace(" ", "-", $term->name)).'" href="#">'.$term->name.'</a></li>';
            }
        }
        ?>
    </ul>
</div><div class="clear"></div>

<!-- Portfolio
================================================== -->

<div class="sixteen columns row teasers portfolio nopadding"> 

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

    <?php   
        $custom = get_post_custom($post->ID);
        $foliocatlist = get_the_term_list( $post->ID, $pcat, '', ', ', '' );
        $entrycategory = get_the_term_list( $post->ID, $pcat, '', '_', '' );
        $entrycategory = strip_tags($entrycategory);
        $entrycategory = strtolower($entrycategory);
        $entrycategory = str_replace(' ', '-', $entrycategory);
        $entrycategory = str_replace('_', ' ', $entrycategory);
        $entrytitle = get_the_title();
        $blogimageurl = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
        if($blogimageurl==""){
            $theblogimage = $templateurl.'/images/demo/460x259.jpg';
        }else{
            $theblogimage = aq_resize( $blogimageurl, 420, $tune_portfoliolock, true );
        }

        $foliocustoms = getOptions($post->ID);
        if (isset($foliocustoms["postformat_detail"])){$tune_postdetail = $foliocustoms['postformat_detail'];}else{$tune_postdetail = 0;}
        if (isset($foliocustoms["postformat_type"])){$tune_postformat = $foliocustoms['postformat_type'];}else{$tune_postformat = 0;}
        if (isset($foliocustoms["postformat_video"])){$tune_postvideo = $foliocustoms['postformat_video'];}else{$tune_postvideo = "";}
        if (isset($foliocustoms["postformat_lightbox"])){$tune_lightbox = $foliocustoms['postformat_lightbox'];}else{$tune_lightbox = 0;}
        if($tune_lightbox==1){ $lblink = $blogimageurl; } else if($tune_lightbox==2){ $lblink = 'http://www.youtube.com/watch?v='.$tune_postvideo.'&amp;width=720&amp;height=435'; } else if($tune_lightbox==3){ $lblink = 'http://vimeo.com/'.$tune_postvideo.'&amp;width=720&amp;height=405'; }
        if($tune_lightbox!=0 && $tune_postdetail==0){ $notalonemod = "notalone"; } else { $notalonemod = ""; }
    ?>

    <div class="four columns teaser all-group <?php echo $entrycategory ?>">
        <div class="mediaholder">
            <?php echo '<img src="'.$theblogimage.'" alt="" />'; ?>
            <div class="cover"></div>
            <?php if($tune_postdetail==0){ ?>
                <a href="<?php the_permalink(); ?>"><div class="link <?php echo $notalonemod ?>"></div></a>
            <?php } ?>
            <?php if($tune_lightbox!=0){ ?>
                <a title="<?php echo $entrytitle ?>" href="<?php echo $lblink ?>" data-rel="prettyPhoto[folio]"><div class="show <?php echo $notalonemod ?>"></div></a>
            <?php } ?>
        </div>
        <div class="topline">
        <?php if($tune_postdetail==0){ ?><a href="<?php the_permalink(); ?>"><?php echo $entrytitle ?></a><?php } else { ?><?php echo $entrytitle ?><?php } ?>
        </div>
        <div class="subline"><?php echo $foliocatlist ?></div>
    </div>





    <?php endwhile; ?>







<!-- Pagination -->

    <?php if(function_exists('pagination')){ pagination(); }else{ paginate_links(); } ?>

<!-- Pagination End -->







    <?php else : ?>
    <div class="eleven columns row alpha">
        <p><?php _e('Oops, we could not find what you were looking for...', 'tune'); ?></p>
    </div>
    <?php endif; ?>

    <?php 
    $wp_query = null; 
    $wp_query = $temp;
    wp_reset_query();
    ?>

    <div class="clear"></div>
</div><div class="clear"></div>

<!-- Space Adjuster
================================================== -->

<div class="sixteen columns bottomadjust"></div><div class="clear"></div>

<script type="text/javascript">                                 
    jQuery(document).ready(function() {
        jQuery('.portfolio4column').tpportfolio({
            row:4,
            portfolioContainer:'.portfolio'
        });
    });
</script>



<?php get_footer(); ?>

如果有人对如何解决这个问题有任何建议。谢谢!

4

1 回答 1

0

你说的,你已经加了poats_per_page,加上paged那个,即

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
    'posts_per_page' => 10,
    'paged' => $paged
);
于 2013-09-15T19:02:26.967 回答