首页 问答 正文

如何在wordpress中使用归档页面?

注册会员 / 悠然自学 / 2023-06-11/ 浏览 151 次

在WordPress中使用归档页面,可以按照以下步骤进行操作:

1.在WordPress后台,创建一个新页面,例如“归档页面”。

2.在页面编辑器中,输入以下代码:

[archives] 

3.保存并发布页面。

4.访问该页面,就会显示博客文章的归档列表。

以上代码是使用默认设置来显示归档列表的简单方法。如果您想进行更多的自定义,例如设置归档列表的样式和显示,可以使用以下示例代码:

<?php
/**
 * Template Name: Archives
 */

get_header(); ?>

<section id="primary" class="site-content">
    <div id="content" role="main">

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

            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                <header class="entry-header">
                    <h1 class="entry-title"><?php the_title(); ?></h1>
                </header><!-- .entry-header -->

                <div class="entry-content">
                    <?php the_content(); ?>

                    <h2><?php _e( 'Archives by Month:', 'twentythirteen' ); ?></h2>
                    <ul>
                        <?php wp_get_archives( array( 'type' => 'monthly', 'limit' => 12 ) ); ?>
                    </ul>

                    <h2><?php _e( 'Archives by Subject:', 'twentythirteen' ); ?></h2>
                    <ul>
                        <?php wp_list_categories( array( 'title_li' => '' ) ); ?>
                    </ul>
                </div><!-- .entry-content -->
            </article><!-- #post -->

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

    </div><!-- #content -->
</section><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?> 

此代码将创建一个自定义页面模板,包括按月份和主题的归档列表。使用自定义CSS样式表和HTML标记来定制归档列表的样式和外观。

大家谈论
    我的见解