wordpress自定义帖子类型最后四个

时间:2013-11-08 12:53:55

标签: wordpress

我在wordpress中创建自定义帖子类型以创建一个组合,然后在主页中我希望这个脚本显示我的最后四个客户端

                    <!-- INIZIO LOOP PER L'ESTRAZIONE E RICHIAMO DATI PORTFOLIO-->
                <?php

                    //Array di configurazione Loop
                    $args = array(
                        'post_type' => 'portfolio',
                        'post_per_page' => 4
                    );
                    $nuovo_loop = new WP_Query( $args );
                        if( $nuovo_loop->have_posts() ) :
                        while( $nuovo_loop->have_posts() ) : $nuovo_loop->the_post();
                ?>

                <!-- Cosa fare dentro il loop -->
                <div class="grid_3 portElements">

                    <div class="full_overlay">
                        <div class="content">
                            <span class="portfolioimage">
                                <p><?php the_title(); ?></p>
                                <a href="<?php the_permalink(); ?>" target="_self">
                                    <span class="DWSdetails">dettagli</span>
                                </a>
                                <a href="<?php
  $myExcerpt = get_the_excerpt();
  $tags = array("<p>", "</p>");
  $myExcerpt = str_replace($tags, "", $myExcerpt);
  echo $myExcerpt;
  ?>" id="outLink" target="_blank">
                                    <span class="view">visita </span>
                                </a>

                            </span>
                        </div>
                        <div class="portImage" >
                             <?php if ( has_post_thumbnail() ) {
                                        the_post_thumbnail('thumbImage');
                                    }else{
                                        echo '<img src="http://www.dywes.com/wp-content/themes/dywes/images/workinprogress.png" />';
                                    }
                            ?>
                        </div>

                    </div>
                </div>
                <?php
                    endwhile;
                    else:
                ?>  
                <!-- Cosa fare se il loop non trova niente -->
                <?php 
                    endif;
                    wp_reset_postdata();
                ?>


            </div>
                <!--FINE LOOP PORTFOLIO-->

但是当我重新加载页面时,我看到了所有客户...... 我怎样才能看到其中的4个呢?

2 个答案:

答案 0 :(得分:0)

$args = array(
                    'post_type' => 'portfolio',
                    'posts_per_page' => 4,
                    'order' => 'DESC',
                    'orderby' => 'post_date'
                );

这应该显示最后4。 您可以在Codex

中找到更多详细信息

答案 1 :(得分:0)

你的论点$ args是错误的,它是posts_per_page,而不是post_per_page

$args = array(
                    'post_type' => 'portfolio',
                    'posts_per_page ' => 4
                );