【问题标题】:Blog page showing same as homepage博客页面显示与主页相同
【发布时间】:2013-08-12 21:03:14
【问题描述】:

我正在尝试将我的帖子发布在另一个页面(博客)上,并且我的“主页”页面显示为我的首页。两个页面都有分配给它们自己的模板(家对家,博客对博客)。

在阅读设置中,我将首页设置为主页,将帖子页面设置为博客。但是当我访问 url.com/blog 时,它显示的模板与我的主页相同。我不确定为什么它不会显示我的两篇博文。

在我的 home.php 模板中,我有以下代码,这可能是问题吗?

<!-- Display featured images -->
    <?php 
        $args = array('post_type'=> 'page');
        query_posts( $args );
    ?>

<!-- Get featured images -->
    <div class="main-thumb left">
        <?php 
            if ( have_posts() ) {
                while ( have_posts() ) {
                    the_post(); 
            ?>
                <li>
                    <a href="<?php echo get_permalink(); ?>">
                        <div class="tint">
                            <div class="overlay caps">
                                <?php 
                                    echo(types_render_field("top-overlay", array("output"=>"html")));
                                ?>
                                <?php 
                                    echo(types_render_field("bottom-overlay", array("output"=>"html")));
                                ?>
                            </div> <!-- end .OVERLAY-->

                            <?php the_post_thumbnail(); ?>
                        </div> <!-- end .TINT-->
                    </a>
                </li>
        <?php
                } 
            } 
        ?>
    </div> <!-- end .MAIN-THUMB-->

【问题讨论】:

标签: php wordpress blogs


【解决方案1】:

home.php 根据模板层次无论如何都会被用作主页:

  1. WordPress 首先判断是否有静态首页。如果已设置静态首页,则 WordPress 会根据页面模板层次结构加载该页面。

  2. 如果尚未设置静态首页,则 WordPress 会查找名为 home.php 的模板文件并使用它来生成请求的页面。

【讨论】:

  • 好的,所以我在阅读设置中将主页设为“主页”没有什么坏处吗?
  • 您是否为“博客”创建了页面模板、发布并确保其正确加载?
  • 谢谢,没有意识到这一点。也不知道我必须在模板中实际添加代码。
猜你喜欢
  • 1970-01-01
  • 2017-07-26
  • 1970-01-01
  • 2019-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多