【问题标题】:cycle next page wordpress order by post title按帖子标题循环下一页wordpress顺序
【发布时间】:2013-10-12 14:19:14
【问题描述】:

我正在为我的网站使用 Cycle jquery。 我添加了一个 php 代码,在我的幻灯片末尾有一个链接可以转到下一页。 我希望我的页面按字母顺序排序,但它不起作用...... 我添加了“orderby = post_title”但仍然无法正常工作...... 有人可以帮我吗? 这是我的 PHP 代码:

function dbdb_next_page_link() {
        global $post;
        if ( isset($post->post_parent) && $post->post_parent > 0 ) {
            $children = get_pages('&orderby=menu_order&order=ASC&child_of='.$post->post_parent.'&parent='.$post->post_parent);
        }
//print_r($children);
        // throw the children ids into an array
        foreach( $children as $child ) { $child_id_array[] = $child->ID; }
        $next_page_id = relative_value_array($child_id_array, $post->ID, 1);
        $output = '';

        if( '' != $next_page_id ) {

            $output .= '<a href="' . get_page_link($next_page_id) . '">'. get_the_title($next_page_id) . ' &raquo;</a>';

        }

        return get_page_link($next_page_id);

    }

还有一个 jsfiddle 链接:http://jsfiddle.net/KvBRV/

....

我的“选择类型”菜单也有同样的问题,我的页面没有按字母顺序排序,我不知道为什么,这是我的 php 代码:

<div class="styled-select">
<?php

if(!$post->post_parent){

    $children = get_pages(array(
        'child_of' => $post->ID,
        'post_type' => 'page',
        'post_status' => 'publish',
        'sort_order' => 'ASC',
        'sort_column' => 'post_title',
    ));

}else{

    $children = get_pages(array(
        'child_of' => $post->post_parent,
        'post_type' => 'page',
        'post_status' => 'publish',
        'sort_order' => 'ASC',
        'sort_column' => 'post_title',
    ));
}

if ($children) {
    echo '<select name="" onchange="location = this.options[this.selectedIndex].value;">';
    echo '<option>'. 'A - Z' .'</option>';

    function getInitials($name){
    //split name using spaces
    $words=explode(" ",$name);
    $inits='';
    //loop through array extracting initial letters
    foreach($words as $word){
        $inits = strtoupper(substr($word,0,1));
        break;
    }
    return $inits; 
}
$currval = "";

    foreach($children as $child){
    //print_r($child);
    $permalink = get_permalink($child->ID);
    $post_title = strtoupper($child->post_title);
    $initial = getInitials($child->post_title);
    if($initial!='' && $currval != $initial ) {
        $currval = $initial;
        echo '<optgroup label="'.$initial.'""></optgroup>';
    }
    echo '<option value="'.$permalink.'">'.$post_title.'</option>';
    }
    echo '</select>';


} ?>


<!-- FIN MENU DEROULANT A-Z -->


</div>

还有一个 jsfiddle 链接:http://jsfiddle.net/Zp3Lt/

非常感谢您的帮助!

马蒂厄

【问题讨论】:

    标签: php wordpress title jquery-cycle alphabetical


    【解决方案1】:

    get_pages 不接受任何名为 orderbyorder 的参数,而是使用 sort_columnsort_order ..

    所以你的代码是

    if ( isset($post->post_parent) && $post->post_parent > 0 ) {
                $children = get_pages('sort_column=post_title&sort_order=ASC&child_of='.$post->post_parent.'&parent='.$post->post_parent);
            }
    

    参考这里

    Get Pages

    【讨论】:

    • 谢谢,但它仍然无法正常工作......在我的第一个 php 代码中,我用你的代码替换了,但没有效果......我的第二个代码,我使用的是 sort_column 和 sort_order ......所以它应该工作,我不明白,你呢? @wordpresser
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-16
    相关资源
    最近更新 更多