WordPress Twenty Fifteen - 仅列出类别

时间:2015-07-13 09:16:10

标签: php wordpress

我正在使用带有Twenty Fifteen主题的WordPress。

我想在类别页面中仅列出文章标题。

默认方式列出整篇文章,但这不是我想要的。 我只需要标题。 理想情况下,它还会按标题名称(升序)对帖子进行排序。

默认代码如下所示:

      <?php
    /**
     * The template for displaying archive pages
     *
     * Used to display archive-type pages if nothing more specific matches a query.
     * For example, puts together date-based pages if no date.php file exists.
     *
     * If you'd like to further customize these archive views, you may create a
     * new template file for each one. For example, tag.php (Tag archives),
     * category.php (Category archives), author.php (Author archives), etc.
     *
     * @link https://codex.wordpress.org/Template_Hierarchy
     *
     * @package WordPress
     * @subpackage Twenty_Fifteen
     * @since Twenty Fifteen 1.0
     */

get_header(); ?>
<section id="primary" class="content-area">
    <main id="main" class="site-main" role="main">

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

        <header class="page-header">
            <?php
                the_archive_title( '<h1 class="page-title">', '</h1>' );
                the_archive_description( '<div class="taxonomy-description">', '</div>' );
            ?>
        </header><!-- .page-header -->

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

            /*
             * 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( 'content', get_post_format() );

        // End the loop.
        endwhile;

        // Previous/next page navigation.
        the_posts_pagination( array(
            'prev_text'          => __( 'Previous page', 'twentyfifteen' ),
            'next_text'          => __( 'Next page', 'twentyfifteen' ),
            'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyfifteen' ) . ' </span>',
        ) );

    // If no content, include the "No posts found" template.
    else :
        get_template_part( 'content', 'none' );

    endif;
    ?>

    </main><!-- .site-main -->
</section><!-- .content-area -->

我尝试编辑这部分代码并尝试以下内容:

get_template_part( 'title', get_post_format() );

和其他变化,但没有一个工作。

1 个答案:

答案 0 :(得分:1)

当你在Wordpress循环中时,你可以像这样使用the_title()

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


?> 
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a><br />
<?php
        // End the loop.
        endwhile;

        // Previous/next page navigation.
        the_posts_pagination( array(
            'prev_text'          => __( 'Previous page', 'twentyfifteen' ),
            'next_text'          => __( 'Next page', 'twentyfifteen' ),
            'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyfifteen' ) . ' </span>',
        ) );

有关详细信息,请参阅此页

https://codex.wordpress.org/Function_Reference/the_title