drtsd7864 2019-05-16 10:31
浏览 75

Wordpress | 按归档过滤帖子仍显示所有年份且未选中

I have set up a WP_Query within my archive.php page. This is so I can do different things such as pagination etc. I also have two drop down filters categories and archive (yearly).

When selecting a year I am taken to a page with the following URL www.mysite.com/2018/ and the pagination also works www.mysite.com/2018/page/2/. However when filtering the site by year its showing posts from all years and not the selected year.

Here is my WP_query code:

<?php
    $currentCategory = single_cat_title("", false);

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
        'category_name' => $currentCategory,
        'paged'=> $paged,
        'posts_per_page' => '9'
    );
    $query = new WP_Query( $args );

    $tax = 'category';
    $terms = get_terms( $tax );
    $count = count( $terms );

    if ( $count > 0 ): ?>
    <div class="row">
        <div class="col-md-12">
            <?php if (is_date()) {?>
                <h1 class="pagetitle"><?php the_time('Y'); ?></h1>
            <?php } else {?>
                <h1 class=""><?php echo $currentCategory?></h1>
            <?php } ?>
        </div>
    </div>  
    <div class="clearfix">
        <div class="select-filter-wrapper float-left">
            <div class="clearfix">
                <p class="p-filter float-left">Categories:</p>
                <div id="category-filter" class="current-filter float-left">
                    <div id="category-select" class="select-option">
                        <?php if (is_date()) {?>
                            <div id="category-select" class="select-option"><p>All</p></div>
                        <?php } else {?>
                            <p><?php echo $currentCategory?></p>
                        <?php } ?>

                    </div>

                    <ul id="category-list" class="select-dropdown">
                        <li class="cat-item cat-item-all">
                            <a href="<?php echo get_permalink( get_option( 'page_for_posts' ) ); ?>">All</a>
                        </li>
                        <?php
                        $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); 
                        $currentTerm = $term->term_taxonomy_id;
                        wp_list_categories( array(
                            'orderby'            => 'description',
                            'order'              => 'ASC',
                            'style'              => 'list',
                            'title_li'           => __( '' ),
                            'taxonomy' => 'category',
                            'walker'             => null,
                            'current_category' => ( isset($currentTerm) ) ? $currentTerm : null
                        ));
                        ?>
                    </ul>
                </div>
            </div>
        </div>

        <div class="select-filter-wrapper float-left">
            <div class="clearfix">
                <p class="p-filter float-left">Archive:</p>
                <div id="category-filter" class="current-filter float-left">
                    <div id="category-select" class="select-option">
                        <?php if (is_date()) {?>
                            <p><?php the_time('Y'); ?></p>
                        <?php } else {?>
                            <p>Year</p>
                        <?php } ?>

                    </div>

                    <ul id="category-list" class="select-dropdown">
                        <!--<li class="current-cat"><a href="<//?php echo get_permalink( get_option( 'page_for_posts' ) ); ?>">All</a></li>-->
                        <?php $args = array(
                            'type'            => 'yearly',
                            'limit'           => '',
                            'format'          => 'html', 
                            'before'          => '',
                            'after'           => '',
                            'show_post_count' => false,
                            'echo'            => 1,
                            'order'           => 'DESC',
                            'post_type'     => 'post'
                        );

                          wp_get_archives( $args ); 

                        ?>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <?php endif;
    if ( $query->have_posts() ): ?>
    <div class="row row-eq-height">
        <?php while ( $query->have_posts() ) : $query->the_post(); ?>
        <div class="col-md-4 o-mg-btm-md">
            <?php get_template_part( 'template-parts/content', get_post_type() );?>
        </div>
        <?php endwhile; ?>
    </div>

    <?php wordpress_numeric_post_nav(); ?>

    <?php endif; ?>

Do I need add something else within my $args to get the yearly filtering to work?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 python天天向上类似问题,但没有清零
    • ¥30 3天&7天&&15天&销量如何统计同一行
    • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
    • ¥15 C#调用python代码(python带有库)
    • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
    • ¥15 活动选择题。最多可以参加几个项目?
    • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
    • ¥15 vs2019中数据导出问题
    • ¥20 云服务Linux系统TCP-MSS值修改?
    • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)