主页不符合仅在第一页上发布的每页帖子设置

时间:2012-09-06 作者:Jeremy

我正在为我的办公室制作一个自定义模板。我有一个静态首页和一个静态主页来显示博客帖子。我有一些小问题,在解决每个问题时,我必须提出一些其他问题。。。无论如何,这个问题对我来说很有趣。

在开发过程中,我将每页的帖子设置为3(设置>阅读)。在博客页面(home.php)上,我确实看到了我的最新帖子,这很好。问题是主页显示的是大约8篇博客文章,而不是设置为显示的3篇。我没有对查询做任何自定义操作,只是使用循环来显示帖子内容。

分页工作正常,功能如预期。所有分页的页面仅显示3篇文章,并且每一页都是正确的文章。唯一的问题是主页首先显示8篇文章,而不是设置中设置的3篇。

在此方面的任何帮助都将不胜感激。我试着搜索,但找不到任何人有这个问题,如果这是一个重复的帖子,很抱歉,希望我能得到一个正确的方向推动。

我还检查了“211”主题,同样的问题也出现了。这是我从中复制了一些逻辑的模板。

我禁用了所有插件,问题仍然存在。我使用的唯一插件是WordPress SEO和WP Lightbox 2。即使禁用了它们,问题仍然会发生。

如果我将每页的帖子数增加到15篇,它将显示17篇。。。如果我把它增加到6,我会显示10。如果我将数字增加到7或8,我将显示11个帖子。如果我将其设置为9,则显示12。10显示13。。。。12显示14。。。正如你所看到的,非常令人沮丧。我更改查询的唯一地方是首页,但我怀疑这会影响主页。我基本上在首页上做了一个自定义查询,只显示最后6条粘性帖子。我确保之后重置查询是安全的。仍然不知道为什么会发生这种情况。这让我发疯了!

我已提供以下代码:

home.php

<?php 
/*
Template Name: Home Page (Blog Roll)
*/
?>

<?php get_header(); ?>

<div id="main">
    <div id="content" class="list-box">
        <?php
        /* Run the loop to output the page.
        * If you want to overload this in a child theme then include a file
        * called loop-page.php and that will be used instead.
        */
        get_template_part( \'loop\', \'single\' );
        ?>
        <div class="page-nav">
            <?php if (get_next_posts_link()): ?>
            <span class="nav-button older-posts"><?php next_posts_link( \'&laquo; Older posts\'); ?></span>
            <?php 
            endif;
            if (get_previous_posts_link()): ?>
            <span class="nav-button newer-posts"><?php previous_posts_link( \'Newer posts &raquo;\' ); ?></span>
            <?php endif; ?>
        </div>        
    </div>
    <?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>

loop-single.php

<?php
/**
* The loop that displays a single post.
*
* The loop displays the posts and the post content. See
* http://codex.wordpress.org/The_Loop to understand it and
* http://codex.wordpress.org/Template_Tags to understand
* the tags used in it.
*
* This can be overridden in child themes with loop-single.php.
*
* @package WordPress
* @subpackage EHRScopev2
*/
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <div class="box">
            <div class="box-holder">
                <div class="box-frame">
                    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                        <h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                        <em class="meta"><?php ehrscope_posted_on(); ?>&nbsp;|&nbsp;<span class="total-comments"><?php comments_popup_link(); ?></span></em>
                        <?php
                        if (!is_single() && has_excerpt()):
                            the_excerpt();
                        else:
                            the_content(__(\'Continue reading\', \'ehrscope\') . \': <em>\' . the_title(\'\', \'\', false) . \'</em>\');
                        endif;
                        ?>
                        <div class="clear"></div>
                        <?php
                        if (is_single()):
                            ehrscope_wp_link_pages();
                            $tags = wp_get_post_tags($post->ID);
                            ?>
                            <p class="entry-meta"><?php ehrscope_show_tags(); ?></p>
                            <?php if ($tags): ?>
                                <a href="javascript:void(0);" id="toggle-related-posts" class="button"><?php _e(\'Show Related Posts\', \'ehrscope\'); ?></a>
                                <?php
                            endif;
                        endif;
                        ?>
                    </div>
                </div>
            </div>
        </div>

        <?php if (is_single()): ?>
            <div class="box" id="related-posts-cage">
                <div class="box-holder">
                    <div class="box-frame">
                        <div>
                            <?php if (is_single()): ?>
                                <?php
                                if ($tags):
                                    $tag_ids = array();
                                    foreach ($tags as $individual_tag) {
                                        $tag_ids[] = $individual_tag->term_id;
                                    }
                                    $args = array(
                                        \'tag__in\' => $tag_ids,
                                        \'post__not_in\' => array($post->ID),
                                        \'posts_per_page\' => 10, // Number of related posts to display.
                                        \'caller_get_posts\' => 1
                                    );
                                    $my_query = new WP_Query($args);
                                    if ($my_query->have_posts()):
                                        ?>
                                        <h3><?php _e(\'Related Posts\', \'ehrscope\'); ?></h3>
                                        <ul>
                                            <?php
                                            while ($my_query->have_posts()) : $my_query->the_post();
                                                ?>
                                                <li>
                                                    <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
                                                    &nbsp;
                            <!--                                                <span class="related-posts-date"><?php the_time(\'F jS, Y\'); ?></span>-->
                                                </li>
                                                    <?php
                                            endwhile;
                                            ?>
                                        </ul>
                                        <?php
                                    endif;
                                endif;
                            endif;
                            ?>
                        </div>
                    </div>
                </div>
            </div>
            <?php
        endif;
        comments_template(\'\', true);
    endwhile;
else:
    ?>
    <div class="box">
        <div class="box-holder">
            <div class="box-frame">
                <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                    <h2><?php _e(\'No Results\', \'ehrscope\'); ?></h2>
                    <p><?php _e(\'Sorry, no posts matched your criteria.\', \'ehrscope\'); ?></p>
                </div>
            </div>
        </div>
    </div>
<?php endif; ?>
目录$wp_query:

Array
(
    [page] => 0
    [pagename] => blog
    [error] => 
    [m] => 0
    [p] => 0
    [post_parent] => 
    [subpost] => 
    [subpost_id] => 
    [attachment] => 
    [attachment_id] => 0
    [name] => 
    [static] => 
    [page_id] => 0
    [second] => 
    [minute] => 
    [hour] => 
    [day] => 0
    [monthnum] => 0
    [year] => 0
    [w] => 0
    [category_name] => 
    [tag] => 
    [cat] => 
    [tag_id] => 
    [author_name] => 
    [feed] => 
    [tb] => 
    [paged] => 0
    [comments_popup] => 
    [meta_key] => 
    [meta_value] => 
    [preview] => 
    [s] => 
    [sentence] => 
    [fields] => 
    [category__in] => Array
        (
        )

    [category__not_in] => Array
        (
        )

    [category__and] => Array
        (
        )

    [post__in] => Array
        (
        )

    [post__not_in] => Array
        (
        )

    [tag__in] => Array
        (
        )

    [tag__not_in] => Array
        (
        )

    [tag__and] => Array
        (
        )

    [tag_slug__in] => Array
        (
        )

    [tag_slug__and] => Array
        (
        )

    [ignore_sticky_posts] => 
    [suppress_filters] => 
    [cache_results] => 1
    [update_post_term_cache] => 1
    [update_post_meta_cache] => 1
    [post_type] => 
    [posts_per_page] => 3
    [nopaging] => 
    [comments_per_page] => 5
    [no_found_rows] => 
    [order] => DESC
)

2 个回复
最合适的回答,由SO网友:Jeremy 整理而成

看来这是个致命的错误。

粘性帖子被添加到页面顶部,从而增加了初始blogroll上的帖子数量。我只需将粘性帖子从粘性中移除,这就解决了问题。

我只在首页使用粘贴帖,我不希望它们出现在首页的顶部。php页面。

谢谢你的帮助!

Updated home.php

<?php
/*
Template Name: Home Page (Blog Roll)
*/
?>

<?php get_header(); ?>

<div id="main">
    <div id="content" class="list-box">
        <?php
        // Prevents sticky posts form always being at the top of the page. (still shows them in normal sort order)
        $queryObject = new WP_Query(array(
            \'caller_get_posts\' => \'1\',
            \'paged\' => get_query_var(\'paged\')
        ));        
        /* Run the loop to output the page.
        * If you want to overload this in a child theme then include a file
        * called loop-page.php and that will be used instead.
        */
        get_template_part(\'loop\', \'custom-query\');
        ehrscope_posts_page_navigation();
        ?>
    </div>
    <?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>

loop-custom-query.php

<?php
/**
* The loop that displays a single post.
*
* The loop displays the posts and the post content. See
* http://codex.wordpress.org/The_Loop to understand it and
* http://codex.wordpress.org/Template_Tags to understand
* the tags used in it.
*
* This can be overridden in child themes with loop-single.php.
*
* @package WordPress
* @subpackage EHRScopev2
*/
global $queryObject;
?>
<?php if ($queryObject->have_posts()) : while ($queryObject->have_posts()) : $queryObject->the_post(); ?>
        <div class="box">
            <div class="box-holder">
                <div class="box-frame">
                    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                        <h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                        <em class="meta"><?php ehrscope_posted_on(); ?>&nbsp;|&nbsp;<span class="total-comments"><?php comments_popup_link(); ?></span></em>
                        <?php
                        if (!is_single() && has_excerpt()):
                            the_excerpt();
                        else:
                            the_content(__(\'Continue reading\', \'ehrscope\') . \': <em>\' . the_title(\'\', \'\', false) . \'</em>\');
                        endif;
                        ?>
                        <?php
                        if (is_single()):
                            ehrscope_wp_link_pages();
                            $tags = wp_get_post_tags($post->ID);
                            ?>
                            <p class="entry-meta"><?php ehrscope_show_tags(); ?></p>
                            <?php if ($tags): ?>
                                <a href="javascript:void(0);" id="toggle-related-posts" class="button"><?php _e(\'Show Related Posts\', \'ehrscope\'); ?></a>
                                <?php
                            endif;
                        endif;
                        ?>
                    </div>
                </div>
            </div>
        </div>

        <?php if (is_single()): ?>
            <div class="box" id="related-posts-cage">
                <div class="box-holder">
                    <div class="box-frame">
                        <div>
                            <?php if (is_single()): ?>
                                <?php
                                if ($tags):
                                    $tag_ids = array();
                                    foreach ($tags as $individual_tag) {
                                        $tag_ids[] = $individual_tag->term_id;
                                    }
                                    $args = array(
                                        \'tag__in\' => $tag_ids,
                                        \'post__not_in\' => array($post->ID),
                                        \'posts_per_page\' => 10, // Number of related posts to display.
                                        \'caller_get_posts\' => 1
                                    );
                                    $my_query = new WP_Query($args);
                                    if ($my_query->have_posts()):
                                        ?>
                                        <h3><?php _e(\'Related Posts\', \'ehrscope\'); ?></h3>
                                        <ul>
                                            <?php
                                            while ($my_query->have_posts()) : $my_query->the_post();
                                                ?>
                                                <li>
                                                    <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
                                                    &nbsp;
                            <!--                                                <span class="related-posts-date"><?php the_time(\'F jS, Y\'); ?></span>-->
                                                </li>
                                                    <?php
                                            endwhile;
                                            ?>
                                        </ul>
                                        <?php
                                    endif;
                                endif;
                            endif;
                            ?>
                        </div>
                    </div>
                </div>
            </div>
            <?php
        endif;
        comments_template(\'\', true);
    endwhile;
else:
    ?>
    <div class="box">
        <div class="box-holder">
            <div class="box-frame">
                <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                    <h2><?php _e(\'No Results\', \'ehrscope\'); ?></h2>
                    <p><?php _e(\'Sorry, no posts matched your criteria.\', \'ehrscope\'); ?></p>
                </div>
            </div>
        </div>
    </div>
<?php endif; ?>

SO网友:Thomas Frank

在主题的整个目录中搜索函数“is\\u home()”和“is\\u front\\u page()”。我能想到的唯一一件事是,在某个地方写了一个函数,使首页有8篇文章,而不管在博客的其余部分,每页设置了多少篇文章。

结束

相关推荐

Activate blog hook

我想在wordpress multisite中激活博客时挂接一个函数。我有这个,add_filter( \'add_signup_meta\', \'custom_add_signup_meta\' ); function custom_add_signup_meta ( $blogmeta = array() ) { $the_country = $_POST[\'country-origin\']; $d_currency =