导致循环显示张贴更多的功能(空)

时间:2016-02-09 作者:lucasbento

通过使用功能:

add_action( \'pre_get_posts\', \'add_custom_post_types_to_loop\' );

function add_custom_post_types_to_loop( $query ) {
    if ( is_home() && $query->is_main_query() ) {
        $query->set( \'post_type\', \'property\' );
    $query->set( \'posts_per_page\', 5 );
    }
    return $query;
}
我遇到以下问题(溢出后):

enter image description here

我的代码循环如下:

<?php 
    global $post, $query_string, $SMTheme;

    $i=1;

    if (have_posts() ) :  

    if (!isset($_GET[\'ajaxpage\'])) {?>
 <div class=\'articles\'>
    <?php }
    while (have_posts() ) : the_post(); 
    ?>
        <!-- div one-post -->
        <div class=\'one-post\'>
        <!-- div post -->
        <div id="post-<?php the_ID(); ?>" <?php post_class("post-caption"); ?>>


            <?php /* Título */

            if (!is_single()&&!is_page()) { ?>
            <h2><a href="<?php the_permalink(); ?>" title="<?php printf( $SMTheme->_( \'permalink\' ), the_title_attribute( \'echo=0\' ) ); ?>" class=\'post_ttl\'><?php the_title(); ?></a></h2>
            <?php } else { ?>
                <h1><?php the_title(); ?></h1>
            <?php } /* Fim Título */ ?>

            <!-- Paragrafo --><p <?php /* Edição de post e data */if(is_page()) echo \'style="display:none"\' ?>><?php if (!is_page()) {?><span class=\'post-date\'><?php echo get_the_date(); ?></span> <img alt="" src="<?php echo get_template_directory_uri(); ?>/images/smt/category.png"><?php echo $SMTheme->_(\'before-category\'); ?><?php the_category(\',&nbsp;\'); }?>
            <?php if(comments_open( get_the_ID() ))  {
                    ?><img alt="" src="<?php echo get_template_directory_uri(); ?>/images/smt/comments.png"> | <span class="meta_comments"><?php comments_popup_link( $SMTheme->_( \'noresponses\' ), $SMTheme->_( \'oneresponse\' ), $SMTheme->_( \'multiresponse\' ) ); ?></span><?php
                }
                ?><?php edit_post_link( $SMTheme->_( \'edit\' ), \'&nbsp;&nbsp;|&nbsp;&nbsp;<span class="edit-link">\', \'</span>\' ); ?>
                <span>
                    <?php if(function_exists(\'the_views\')) { the_views(); } ?>
                </span>
                </p><?php /* Fim Edição de post e data */ ?><!-- Fim Paragrafo -->

        </div> <!-- Fim div post -->

        <!-- post-body -->
        <div class=\'post-body\'>
            <?php
                /* Miniatura */
                if(has_post_thumbnail())  {
                    ?><?php if (!is_single()) { ?><a href="<?php the_permalink(); ?>" title="<?php printf( $SMTheme->_( \'permalink\' ), the_title_attribute( \'echo=0\' ) ); ?>"><?php the_post_thumbnail(
                        \'post-thumbnail\',
                        array("class" => $SMTheme->get( \'layout\',\'imgpos\' ) . " featured_image")
                    ); ?></a><?php } else { ?>
                        <?php the_post_thumbnail(
                        array(278, 173),
                        array("class" => $SMTheme->get( \'layout\',\'imgpos\' ) . " featured_image")
                    ); ?>
                    <?php }
                }
                /*  Fim Miniatura */

                /* Leia Mais */
                if (!is_single()&&!is_page()) {
                    if ( ! post_password_required() ) { the_excerpt(\'echo=1\'); } else the_content(\'\');
                    ?><a href=\'<?php the_permalink(); ?>\' class=\'readmore\'><?php echo $SMTheme->_( \'readmore\' ); ?></a><?php
                } else {
                    the_content(\'\');

                }

                /* Fim Leia Mais */
            ?>
            <?php wp_link_pages(); ?>
        </div><!-- Fim div post-body -->
        </div><!-- Fim div one-post -->
    <?php endwhile; ?>

    <?php if (!isset($_GET[\'ajaxpage\'])) {?>
 </div><!-- Fim div articles -->
    <?php } ?>


<?php endif;
wp_reset_query(); ?>
有什么建议可以解决吗?

1 个回复
SO网友:Charles Jaimet

如果删除pre_get_posts

无论哪种方式,您都可以尝试将代码包装在条件中。

while (have_posts() ) : the_post(); 
if ( 0 < intval( the_ID() ) {
...
}
endwhile;
这不如限制查询返回的记录数好,但不管怎样,在进行验证时也没有坏处。