我试图个性化一个用underscore.me制作的新主题,但是我似乎不能用循环创建一个新的模板页面,这个循环可以显示一个特定类别的帖子,我如何做到这一点呢?
我要在这里粘贴index.php的underscore.me主题,女巫有一个通用循环,遗憾的是,在模板页面上复制和粘贴这个循环
<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。
<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 -->
发布于 2015-08-31 15:55:26
好消息对你来说,你不需要一个特定的循环一个特定的类别。如果主题中有一个category.php文件,并假设您的类别名为"Lux“,id为"35"。如果您将category.php复制为类别-35.php或类别-lux-cars.php(属于您的类别)。打开带有此类别的帖子时。wordpress调用此文件并在该循环中显示posts。你可以编辑你的分类-35.php和添加任何类别细节或某物。
但是,如果您仍然希望为特定类别设置一个循环,那么您可以使用该代码;
<?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; ?>
https://stackoverflow.com/questions/31689741
复制相似问题