首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用wordpress在underscore.me上创建博客模板页面

使用wordpress在underscore.me上创建博客模板页面
EN

Stack Overflow用户
提问于 2015-07-29 01:21:00
回答 1查看 1.2K关注 0票数 2

我试图个性化一个用underscore.me制作的新主题,但是我似乎不能用循环创建一个新的模板页面,这个循环可以显示一个特定类别的帖子,我如何做到这一点呢?

我要在这里粘贴index.php的underscore.me主题,女巫有一个通用循环,遗憾的是,在模板页面上复制和粘贴这个循环

代码语言:javascript
运行
复制
<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">

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

        <?php if ( is_home() && ! is_front_page() ) : ?>
            <header>
                <h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
            </header>
        <?php endif; ?>

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

            <?php

                /*
                 * Include the Post-Format-specific template for the content.
                 * If you want to override this in a child theme, then include a file
                 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
                 */
                get_template_part( 'template-parts/content', get_post_format() );
            ?>

        <?php endwhile; ?>

        <?php the_posts_navigation(); ?>

    <?php else : ?>

        <?php get_template_part( 'template-parts/content', 'none' ); ?>

    <?php endif; ?>

    </main><!-- #main -->
</div><!-- #primary -->

这是page.php。

代码语言:javascript
运行
复制
<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">

        <?php while ( have_posts() ) : the_post(); ?>

            <?php get_template_part( 'template-parts/content', 'page' ); ?>

            <?php
                // If comments are open or we have at least one comment, load up the comment template.
                if ( comments_open() || get_comments_number() ) :
                    comments_template();
                endif;
            ?>

        <?php endwhile; // End of the loop. ?>

    </main><!-- #main -->
</div><!-- #primary -->
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-31 15:55:26

好消息对你来说,你不需要一个特定的循环一个特定的类别。如果主题中有一个category.php文件,并假设您的类别名为"Lux“,id为"35"。如果您将category.php复制为类别-35.php或类别-lux-cars.php(属于您的类别)。打开带有此类别的帖子时。wordpress调用此文件并在该循环中显示posts。你可以编辑你的分类-35.php和添加任何类别细节或某物。

但是,如果您仍然希望为特定类别设置一个循环,那么您可以使用该代码;

代码语言:javascript
运行
复制
<?php 
$args = array ( 'category' => ID, 'posts_per_page' => 5);
$myposts = get_posts( $args );
foreach( $myposts as $post ) :  setup_postdata($post);
 ?>
//Style Posts here
<?php endforeach; ?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31689741

复制
相关文章

相似问题

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