【发布时间】:2014-03-11 02:41:01
【问题描述】:
我在每个 wordpress 类别中按标题显示帖子 ASC 时遇到困难。我发现的各种代码将按字母顺序列出,但会返回网站上的所有帖子,而不仅仅是用户正在查看的类别。我不想创建多个 category.php 文件或硬编码哪个类别,因为每次将类别添加到网站时我都必须手动设置一个新文件。我只想让代码只查看当前类别,但我不知道在其中编写代码。
我正在使用带有 loop.php 文件的标准 category.php 文件。我删除了所有试图重新排序帖子的代码,但我尝试的示例之一来自该网站:
http://wordpress.org/support/topic/display-posts-in-ascending-order
我的 category.php 是这样的:
<?php get_header(); ?>
<div class="breadcrumbs">
<span> <?php if(function_exists('bcn_display'))
{
bcn_display();
}?></span>
</div>
<!-- section -->
<div class="area">
<section role="main">
<h2><?php single_cat_title(); ?></h2>
<!--<h2><?php the_category(); ?></h2>-->
<?php echo category_description( $category_id ); ?>
<div class="display-posts-listing">
<?php get_template_part('loop'); ?>
</div>
<?php get_template_part('pagination'); ?>
</section>
<!-- /section -->
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
循环是这样的:
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<!-- article -->
<div class="listing-item">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<!-- post title -->
<h3>
<?php the_title(); ?>
</h3>
<!-- /post title -->
<!-- post thumbnail -->
<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
<?php the_post_thumbnail('full'); // Declare pixel size you need inside the array ?>
<?php endif; ?>
<!-- /post thumbnail -->
<!-- post details -->
<!--<span class="author"><?php _e( 'Published by', 'html5blank' ); ?> <?php the_author_posts_link(); ?></span>-->
<!--<span class="comments"><?php comments_popup_link( __( 'Leave your thoughts', 'html5blank' ), __( '1 Comment', 'html5blank' ), __( '% Comments', 'html5blank' )); ?></span>-->
<!-- /post details -->
<?php //html5wp_excerpt('html5wp_index'); // Build your custom callback length in functions.php ?>
<?php the_content(); ?>
<?php edit_post_link(); ?>
</article>
</div>
<!-- /article -->
<?php endwhile; ?>
<?php else: ?>
<!-- article -->
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
</article>
<!-- /article -->
<?php endif; ?>
谢谢
凯茜
【问题讨论】:
-
您可以发布您目前用于构建 wp_query 的代码吗?
-
发布更新谢谢:)
标签: php wordpress title categories