模板页面上只出现一个自定义帖子类型的帖子

时间:2014-10-17 作者:timmyg

我不确定这是否是数据库或模板问题,但在此模板上page 我的自定义帖子类型中只有一篇帖子出现。至少应该有两个。

该页面使用同位素。js脚本,但禁用它并不能缓解问题。

可以找到插件代码here.

模板代码如下:

<?php
/*
Template Name: Exhibitions & Programs
*/
?>
<?php get_header();
    //Set Exhibitions & Programs Query Parameters
if ( false === ( $flagship_exhibitions_query = get_transient( \'flagship_exhibitions_query\' ) ) ) {
                // It wasn\'t there, so regenerate the data and save the transient
                $flagship_exhibitions_query = new WP_Query(array(
                    \'post_type\' => \'ksasexhibits\',
                    \'orderby\' => \'title\',
                    \'order\' => \'ASC\',
                    \'posts_per_page\' => \'-1\'));
                    set_transient( \'flagship_exhibitions_query\', $flagship_exhibitions_query, 2592000 ); } ?>

<div class="row wrapper radius10">
    <div class="twelve columns">
        <section class="row">

            <div class="five columns copy">
            <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                <h2><?php the_title();?></h2>
                <p><?php the_content(); ?></p>
            <?php endwhile; endif; ?>
            </div>

            <div class="seven columns" id="fields_search" role="search">
                <form action="#">
                    <fieldset class="radius10"> 
                        <?php $exhibits = get_terms(\'exhibition_type\', array(
                            \'orderby\'       => \'name\',
                            \'order\'         => \'ASC\',
                            \'hide_empty\'    => true,
                            ));

                        $count_exhibits = count($exhibits);
                        if ($count_exhibits > 0) { ?>
                        <div class="row">
                            <h6>Filter by Exhibit Type:</h6>
                        </div>

                        <div class="row filter option-set" data-filter-group="exhibition_type">
                            <div class="button radio"><a href="#" data-filter="" class="selected">View All</a></div>
                            <?php foreach ( $exhibits as $exhibit ) { ?>
                                <div class="button radio"><a href="#" data-filter=".<?php echo $exhibit->slug; ?>"><?php echo $exhibit->name; ?></a></div>
                            <?php } ?>
                        </div>
                    <?php } ?>
                    <div class="row">
                        <h5>Search by keyword:</h5>     
                        <input type="submit" class="icon-search" placeholder="Search by name/keyword" value="&#xe004;" />
                        <input type="text" name="search" value="" id="id_search" aria-label="Search"  /> 
                    </div>
                    </fieldset>
                </form>
            </div>
        </section>

        <section class="row" id="fields_container" role="main">
            <?php while ($flagship_exhibitions_query->have_posts()) : $flagship_exhibitions_query->the_post(); 
        //Pull discipline array (humanities, natural, social)
        $program_types = get_the_terms( $post->ID, \'exhibition_type\' );
            if ( $program_types && ! is_wp_error( $program_types ) ) : 
                $program_type_names = array();
                $degree_types = array();
                    foreach ( $program_types as $program_type ) {
                        $program_type_names[] = $program_type->slug;
                        $exhibiton_types[] = $program_type->name;
                    }
                $program_type_name = join( " ", $program_type_names );
                $exhibition_type = join( ", ", $exhibition_types );

            endif; ?>

        <!-- Set classes for isotype.js filter buttons -->
        <div class="six columns mobile-four mobile-field  <?php echo $program_type_name . \' \' . $school_name; ?>">

            <div class="twelve columns field radius10" id="<?php echo $program_name; ?>">
            <a href="<?php echo get_permalink() ?>" title="<?php the_title(); ?>" class="field">
                    <?php if ( has_post_thumbnail()) { ?> 
                        <?php the_post_thumbnail(\'rss\'); ?>
                    <?php } ?>              
                    <h3><?php the_title(); ?></h3>
                </a>

                <div class="row">
                    <div class="twelve columns">
                        <p>
                            <?php if (get_post_meta($post->ID, \'ecpt_location\', true)) : ?>
                                        <b>Location:</b>&nbsp;<?php echo get_post_meta($post->ID, \'ecpt_location\', true); ?><br>
                                    <?php endif; ?>
                            <?php if (get_post_meta($post->ID, \'ecpt_dates\', true)) : ?>
                                        <b>Dates:</b>&nbsp;<?php echo get_post_meta($post->ID, \'ecpt_dates\', true); ?><br>
                                    <?php endif; ?>
                            <?php if (get_post_meta($post->ID, \'ecpt_description\', true)) : ?>
                                        <b>Description:</b>&nbsp;<?php echo get_post_meta($post->ID, \'ecpt_description\', true); ?><br>
                                    <?php endif; ?>
                        </p>


                    </div>
                </div>
            </div>
        </a>
    </div>
    <?php endwhile; ?>

    <div class="row" id="noresults">
            <div class="four columns centered">
                <h3> No matching results</h3>
            </div>
    </div>
        </section>

    </div>
</div>
 <!-- End content wrapper -->
    <script src="<?php echo get_template_directory_uri() ?>/assets/javascripts/page.exhibits.js"></script>  <?php get_footer(); ?>

2 个回复
SO网友:maioman

尝试更改的值

\'posts_per_page\' => \'-1\'
这可能会打乱你的查询,

如果需要两个,请尝试将其设置为:

\'posts_per_page\' => \'2\'
也试着把它评论出来。。。。。

我认为这是不言自明的,但要真正理解wp查询,请阅读Codex ref..

SO网友:timmyg

我发现,如果从第8行&;中删除get\\u transient和set\\u transient函数;15然后CPT加载正常。

谢谢大家的帮助!

结束

相关推荐

1 post, 2 templates

我想能够呈现两种不同的风格(2个模板)后。例如,假设我有post ID 133,我希望有两个url来访问它,因此它会呈现不同模板应用的位置。洛雷姆。com/render1/133。com/render2/1333,例如。。。或者可能是这样的:洛雷姆。com/post/133和lorem。com/post/133?模板=2您将如何操作?