Category navigation template

时间:2016-02-17 作者:Meivyn

是否有方法编辑或添加类别导航模板?

更具体地说,对于具有多个页面的新闻类别。

我会这样做:

<footer class="footer">
<nav id="nav-below" class="navigation" role="navigation">
    <div class="nav-previous">
        <a href="#" rel="prev">
            <span class="meta-nav" aria-hidden="true">← Older</span>
        </a>
    </div>
    <div class="nav-next">
        <a href="#" rel="next">
            <span class="meta-nav" aria-hidden="true">Newer →</span> 
        </a>
    </div>
</nav>

另外,我不想看到页码。只有“旧”和“新”。

谢谢你的帮助!

实际上,我使用的是修改后的2016主题。

分类中有代码。php:

    <?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( \'template-parts/content\', get_post_format() );

        // End the loop.
        endwhile;

        // Previous/next page navigation.
        the_posts_pagination( array(
            \'prev_text\'          => __( \'← older\', \'twentysixteen\' ),
            \'next_text\'          => __( \'newer →\', \'twentysixteen\' ),
            \'before_page_number\' => \'<span class="meta-nav screen-reader-text">\' . __( \'\', \'twentysixteen\' ) . \' </span>\',
        ) );

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

    endif;
    ?>
当我尝试用以下内容替换此内容时:

            // Previous/next page navigation.
        the_posts_pagination( array(
            \'prev_text\'          => __( \'← older\', \'twentysixteen\' ),
            \'next_text\'          => __( \'newer →\', \'twentysixteen\' ),
            \'before_page_number\' => \'<span class="meta-nav screen-reader-text">\' . __( \'\', \'twentysixteen\' ) . \' </span>\',
        ) );
我有500个错误。

我想把你的代码放在这里,但真的不知道怎么做。

<nav id="post-pagination" class="navigation" role="navigation">
<div class="nav-previous">
    <?php next_posts_link( \'← Older\', $the_query->max_num_pages ); ?>
</div>
<div class="nav-next">
    <?php previous_posts_link( \'Newer →\' ); ?>
</div>

1 个回复
最合适的回答,由SO网友:Cai 整理而成

WordPress Pagination

您可以使用previous_posts_linknext_posts_link.

<nav id="post-pagination" class="navigation" role="navigation">
    <div class="nav-previous">
        <?php next_posts_link( \'← Older\', $the_query->max_num_pages ); ?>
    </div>
    <div class="nav-next">
        <?php previous_posts_link( \'Newer →\' ); ?>
    </div>
</nav>
这并不重要,但下一个和上一个有相反的类(.nav-previous 在…上next_posts_link() &;.nav-next 在…上previous_posts_link()) 因为:

因为post查询通常按逆时间顺序排序,所以next\\u posts\\u link()通常指向较旧的条目(指向集合的末尾),而PREVISSION\\u link()通常指向较新的条目(指向集合的开头)。

根据您的代码更新,类似这样的东西应该可以使用(虽然我不确定原始版本有什么问题the_posts_pagination?):

    <?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( \'template-parts/content\', get_post_format() );

        // End the loop.
        endwhile;
    ?>

    <nav id="post-pagination" class="navigation" role="navigation">
        <div class="nav-previous">
            <?php next_posts_link( \'← Older\', $the_query->max_num_pages ); ?>
        </div>
        <div class="nav-next">
            <?php previous_posts_link( \'Newer →\' ); ?>
        </div>
    </nav>

    <?php
    // If no content, include the "No posts found" template.
    else :
        get_template_part( \'template-parts/content\', \'none\' );

    endif;
    ?>

相关推荐

Odd spacing in Navigation Bar

我正在重新设计my website, 我很难找到是什么导致导航项目之间的间距(我假设是边距)。我一直在钻研chrome开发工具,但我在任何地方都找不到导致它的原因。请注意,当您在项目之间悬停时,项目之间会有一个明显的白色条带。