簡體   English   中英

我如何獲得 wordpress 插件,以使來自前端的訪問者能夠按升序或降序對帖子進行排序

[英]How can i get a wordpress plugin to enable visitors from frontend to sort posts by ascending order or descending order

任何幫助都感激不盡。 我更喜歡 wordpress 插件。 但如果沒有,我不介意有一個 php 代碼來幫助我。 請記住,我不是 php 專家。

我在 wordpress 法典上看到了這個但不知道如何使用它:

    function wp_list_sort( $list, $orderby = array(), $order = 'ASC', $preserve_keys = false ) {
    if ( ! is_array( $list ) ) {
        return array();
    }
 
    $util = new WP_List_Util( $list );
    return $util->sort( $orderby, $order, $preserve_keys );
}

您可以嘗試使用此插件對您的帖子和帖子類型進行排序

這是一個強大的插件,使用拖放排序 JavaScript 功能訂購帖子和帖子類型對象。

基本上,您可以通過此插件從儀表板訂購,但您也可以將其用於前端,但您需要執行一些自定義代碼。

這是您可以在前端代碼上嘗試的另一種解決方案:

<div class="order-posts">
<div class="order-posts-container">
<?php
    global $wp;
    $current_url = home_url( $wp->request ) . '/'; // last part adds the "/" at the end
?>
<form name="George">
<select class="select-form" name="example" size="1" onChange="go()">
<option selected disabled class="select-form-item 0" value>-- Change order --</option>
<option class="select-form-item 1" value="<?php echo $current_url ?>">Order by default</option>
<option class="select-form-item 2" value="<?php echo $current_url ?>?orderby=title&order=asc">Order from A to Z</option>
<option class="select-form-item 3" value="<?php echo $current_url ?>?orderby=title&order=desc">Order from Z to A</option>
<option class="select-form-item 4" value="<?php echo $current_url ?>?orderby=date&order=desc">Order from new to old</option>
<option class="select-form-item 5" value="<?php echo $current_url ?>?orderby=date&order=asc">Order from old to new</option>
<option class="select-form-item 6" value="<?php echo $current_url ?>?orderby=comment_count&order=desc">Order by comment count 0 - 999</option>
<option class="select-form-item 7" value="<?php echo $current_url ?>?orderby=comment_count&order=asc">Order by comment count 999 - 0</option>
<option class="select-form-item 8" value="<?php echo $current_url ?>?orderby=rand&posts_per_page=10">Random order</option>
</select>
<script type="text/javascript">

function go(){
location=
document.George.example.
options[document.George.example.selectedIndex].value
}
 
</script>
<input type="button" class="button-form" name="sort-posts-button" value="Go!" onClick="go()">
</form>
</div>
</div>
<div style="clear:both"></div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM