开发者

wordpress -override number of posts in loop

开发者 https://www.devze.com 2023-02-05 20:52 出处:网络
See: http://jasondaydesign.com/portfolio开发者_如何学运维 Also, for this custom loop, how would I override the number of posts as set by WP Settings > Reading > show 10 posts.

See: http://jasondaydesign.com/portfolio开发者_如何学运维

Also, for this custom loop, how would I override the number of posts as set by WP Settings > Reading > show 10 posts.

thanks!

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

<?php get_header(); ?>

<ul id="portfolio-filter">
  <li><a href="#all">All</a></li>
  <li><a href="#web-design">Web</a></li>
  <li><a href="#logo-and-branding-design">Logo</a></li>
  <li><a href="#print-and-graphic-design">Print</a></li>
  <li><a href="#sculpture">Sculpture </a></li>
  <li><a href="#for-sale">For Sale </a></li>
 </ul>

        <ul id="portfolio-list">
        <?php query_posts('cat=5&showposts='); ?>
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<!-- ** store the category slugs for each post in a variable $catSlug ** -->
  <li class="<?php foreach((get_the_category()) as $category ) { echo $category->category_nicename . ' '; } ?>all">

 <!-- ** This is my own plugin to get the thumbnail from the post - you may use some custom field you have to get the image. ** -->
                    <a href='<?php the_permalink() ?>' title='<?php the_title(); ?>'><img src='<?php woo_image('width='.$woo_options['woo_thumb_w'].'&height='.$woo_options['woo_thumb_h'].'&class=thumbnail '.$woo_options['woo_thumb_align']); ?>' alt='<?php the_title(); ?>' /></a>

                    <p><?php the_title(); ?></p>
     <p><?php the_excerpt(); ?></p>

                </li>
            <? endwhile; ?>
        <? endif; ?>
  <?php wp_reset_query(); ?>
        </ul>

<?php get_footer(); ?>


Change the line that says

<?php query_posts('cat=5&showposts='); ?>

to say

<?php query_posts('cat=5&showposts=&posts_per_page=10'); ?>


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

Becomes this:

<?php $i = 0; ?>
<?php if ( have_posts() ) : while ( have_posts() && $i < 10 ) : the_post(); ?>
<?php $i++; ?>

Replace the number 10 with whatever number, that being how many times the loop should run.


Easiest way: Custom Post Limits | coffee2code.com

Or work with the post limits in the loop: Function Reference/query posts « WordPress Codex, i.e. Example_3 on that page


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

<?php get_header(); ?>

<ul id="portfolio-filter">
  <li><a href="#all">All</a></li>
  <li><a href="#web-design">Web</a></li>
  <li><a href="#logo-and-branding-design">Logo</a></li>
  <li><a href="#print-and-graphic-design">Print</a></li>
  <li><a href="#sculpture">Sculpture </a></li>
  <li><a href="#for-sale">For Sale </a></li>
 </ul>

    <ul id="portfolio-list">

    <?php $show_posts = get_posts( array( 'numberposts' => 'xx', 'category' => '5' ) ); ?>

    <?php foreach($show_posts as $posts) : the_post(); ?>

        <li class="<?php foreach((get_the_category()) as $category ) { echo $category->category_nicename . ' '; } ?>all">

        <!-- ** This is my own plugin to get the thumbnail from the post - you may use some custom field you have to get the image. ** -->
        <a href='<?php the_permalink() ?>' title='<?php the_title(); ?>'><img src='<?php woo_image('width='.$woo_options['woo_thumb_w'].'&height='.$woo_options['woo_thumb_h'].'&class=thumbnail '.$woo_options['woo_thumb_align']); ?>' alt='<?php the_title(); ?>' /></a>

        <p><?php the_title(); ?></p>
        <p><?php the_excerpt(); ?></p>

        </li>

    <?php endforeach; ?>
0

精彩评论

暂无评论...
验证码 换一张
取 消