Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
499 views
in Technique[技术] by (71.8m points)

javascript - 如何使用下拉列表在wordpress中按评分计数对帖子进行排序?(How to sorting post by rating count in wordpress using dropdown?)

Here is my code

(这是我的代码)

<div class="col-sm-3" class="drop">

            <?php if ( is_archive() ) { ?> 

            <select name="sort-review" id="sortbox" onchange="document.location.href='?'+this.options[this.selectedIndex].value;"> 

            <?php } else { ?>

                <select name="sort-review" id="sortbox" onchange="document.location.href='?s=<?php the_search_query(); ?>&rev=<?php echo $_GET['cat']; ?>&'+this.options[this.selectedIndex].value;">
            <?php } ?>
            <option value="">Sort By</option>
            <option value="orderby=title&order=asc">Ascending</option>
            <option value="orderby=title&order=dsc">Descending</option>
            <option value="orderby=rating&order=asc">Rating Low to High</option>
            <option value="orderby=rating&order=dsc">Rating High to Low</option>
            <option value="orderby=review-count&order=asc">Reviews Lowest to Highest</option>
            <option value="orderby=review-count&order=dsc">Reviews Highest to Lowest</option>
        </select>

    </div>

Here is my javascript code

(这是我的JavaScript代码)

<script type="text/javascript">

    <?php if(( $_GET['orderby'] == 'title') && ($_GET['order'] == 'asc' )) {    ?>
    document.getElementById('sortbox').value='orderby=title&order=asc';

    <?php } elseif (( $_GET['orderby'] == 'title') && ($_GET['order'] == 'dsc' )) { ?>
    document.getElementById('sortbox').value='orderby=review-title&order=dsc';

    <?php } elseif (( $_GET['orderby'] == 'rating') && ($_GET['order'] == 'dsc' )) { ?>
    document.getElementById('sortbox').value='orderby=rating&order=dsc';

    <?php } elseif (( $_GET['orderby'] == 'rating') && ($_GET['order'] == 'asc' )) { ?>
    document.getElementById('sortbox').value='orderby=rating&order=asc';

    <?php } elseif (( $_GET['orderby'] == 'review-count') && ($_GET['order'] == 'asc' )) { ?>
    document.getElementById('sortbox').value='orderby=review-count&order=asc';

    <?php } elseif (( $_GET['orderby'] == 'review-count') && ($_GET['order'] == 'dsc' )) { ?>
    document.getElementById('sortbox').value='orderby=review-count&order=dsc';

    <?php } else { ?>
    document.getElementById('sortbox').value='orderby=title&order=asc';
    <?php } ?>

</script>

With this code Ascending and descending is working perfectly but the rating and review sorting doesn't work properly.

(使用此代码,升序和降序工作正常,但评分和评论排序却无法正常进行。)

  ask by Nicks9789 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...