WordPress所有帖子按年筛选

时间:2018-04-18 作者:Bhupender rathor

WordPress all post filter by year不起作用请帮助我们我的代码是当我选择2016年时,请查看旧的帖子页面是重新排序的bt 2016 post或show

参见本页http://w3ondemand.com/dev/itim/%D7%A2%D7%AA%D7%99%D7%9D-%D7%91%D7%AA%D7%A7%D7%A9%D7%95%D7%A8%D7%AA/test-pagination/

<div class="filter-by">
    <?php
        $selected = \'\';
        if (isset($_GET[\'doc_year\'])) {
        $selected = \'&selected=\' . $_GET[\'doc_year\'];
        }

        wp_dropdown_categories(\'show_option_none=בחר שנה&name=year&taxonomy=years&orderby=name&order=DESC\' . $selected);
    ?>
    <script type="text/javascript"><!--
    var dropdown = document.getElementById("year");
    function onCatChange() {
    if (dropdown.options[dropdown.selectedIndex].value > 0) {
    location.href = "<?php the_permalink(); ?>/?doc_year=" + dropdown.options[dropdown.selectedIndex].value;
    } else
    location.href = "<?php the_permalink(); ?>";
    }
    dropdown.onchange = onCatChange;
    --></script>
</div>

1 个回复
SO网友:Vivekpathak

<select name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">
  <option value=""><?php echo esc_attr( __( \'Select Year\' ) ); ?></option> 
  <?php wp_get_archives( array( \'type\' => \'yearly\', \'format\' => \'option\', \'show_post_count\' => 1 ) ); ?>
</select>
此代码可能会帮助您。

结束