首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在自定义模板中只显示10项

在自定义模板中只显示10项
EN

Stack Overflow用户
提问于 2014-07-11 14:46:25
回答 3查看 110关注 0票数 0

嗨,我在wordpress中有这个模板,我只想显示10个条目,因为现在在wordpress中我有5个条目,但是我想对这个模板做一个例外,我不知道我需要在哪里修改代码才能在这个模板中显示10个条目:

代码语言:javascript
复制
<?php
/*
Template Name: Blog List
*/
?>
<?php get_header(); ?>
<div class="content-wrap">
    <div class="content">
        <?php tie_breadcrumbs() ?>

<div id="content" class="podcast_archive">

        <!--<div class="podcast_full">-->

            <?php if ( have_posts() ) : ?>

                <header><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
                    <h1><?php _e( 'El Jurado del Pueblo' , 'ss-podcasting' ); ?></h1>
                </header>

                <?php
                $feed_url = trailingslashit( home_url() ) . '?feed=podcast';
                $custom_feed_url = get_option('ss_podcasting_feed_url');
                if( $custom_feed_url && strlen( $custom_feed_url ) > 0 && $custom_feed_url != '' ) {
                    $feed_url = $custom_feed_url;
                }
                $itunes_url = str_replace( array( 'http:' , 'https:' ) , 'itpc:' , $feed_url );
                ?>

                <section>

                    <?php
                    /* Start the Loop */
                    while ( have_posts() ) : the_post(); ?>

                        <?php
                        $terms = wp_get_post_terms( get_the_ID() , 'series' );
                        foreach( $terms as $term ) {
                            $series_id = $term->term_id;
                            $series = $term->name;
                            break;
                        }
                        ?>

                        <article class="podcast_episode">

                            <?php if( has_post_thumbnail() ) { ?>
                                <?php $img = wp_get_attachment_image_src( get_post_thumbnail_id() ); ?>
                                <a>" title="<?php the_title(); ?>">
                                    <?php the_post_thumbnail( 'podcast-thumbnail' , array( 'class' => 'podcast_image' , 'alt' => get_the_title() , 'title' => get_the_title() ) ); ?>
                                </a>
                            <?php } ?>

                            <h3>
                                <strong><?php the_title(); ?></strong>
                                <div class="podcast_meta"><?php echo $series; ?><aside></div>
                            </h3>

<div id="audio">
<?php global $ss_podcasting;
$enclosure = $ss_podcasting->get_enclosure( get_the_ID() );
if( $enclosure ) {
    $audio_player = $ss_podcasting->audio_player( $enclosure );
    echo $audio_player;
} ?>
<?php the_content(); ?>
</div>
<div id="audioinfo">
<a>">Descargar Audio</a>
<span class="audiometa">
Tamaño: <?php echo get_post_meta(get_the_ID(), 'filesize', true) ?>
</span>
</div>

<?php echo do_shortcode('[divider]');?>
</article>
                    <?php
                    endwhile;
                    ?>

                </section>

            <?php endif; ?>
<?php wp_pagenavi(); ?>

            <div class="podcast_clear"></div>

        </div>

        <?php comments_template( '', true ); ?>
    </div><!-- .content -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>
?>

我建议你,这样我就可以自己做了:)非常感谢你

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-07-11 14:58:11

您需要在循环之前使用query_posts()函数。

代码语言:javascript
复制
global $wp_query;
$args = array_merge( $wp_query->query_vars, array( 'showposts' => '10' ) );
query_posts( $args );

帖子

票数 1
EN

Stack Overflow用户

发布于 2014-07-11 14:55:08

您需要修改模板的查询。我建议使用查询类。例如:

代码语言:javascript
复制
$args = array( 
    'posts_per_page' => 10
);

$the_query = new WP_Query( $args );

if ( $the_query->have_posts() ) {

    while ( $the_query->have_posts() ) { 
        $the_query->the_post();
        // Loop item here
    }

    wp_reset_postdata();

} else {
    // No results found
}
票数 1
EN

Stack Overflow用户

发布于 2014-07-12 05:25:48

如果是$args = array( 'posts_per_page' => 10 );

不是工作,而是在后台检查设置->阅读,如果有5个帖子而不是只显示5个帖子,就会有一个“博客页面最多显示”。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24700481

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档