簡體   English   中英

wordpress -override循環中的帖子數

[英]wordpress -override number of posts in loop

請參閱: http//jasondaydesign.com/portfolio

此外,對於此自定義循環,我將如何覆蓋“ WP設置”>“閱讀”>“顯示10個帖子”中設置的帖子數量。

謝謝!

<?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(); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

變成這個:

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

將數字10替換為任意數字,即循環應運行多少次。

最簡單的方法: 自定義帖子限制| coffee2code.com

或者在循環中使用發布限制: 函數參考/查詢發布«WordPress Codex ,即該頁面上的Example_3

換行說

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

<?php query_posts('cat=5&showposts=&posts_per_page=10'); ?>
<?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; ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM