【问题标题】:Wordpress list child pages alphabeticallyWordpress 按字母顺序列出子页面
【发布时间】:2011-05-09 21:31:04
【问题描述】:

我有一个包含大约 200 个子页面的父页面,它们构成了一个词典。在父页面的模板中,我想查询有允许以下列表。我想显示以该字母开头的每组单词的第一个字母。如果列表中没有显示字母,则不应显示。

一个

阿尔伯特

艾伦

阿曼达

B

比尔

鲍勃

布鲁诺

C

查尔斯

克里斯汀

等等……

【问题讨论】:

    标签: wordpress listings alphabetical


    【解决方案1】:

    我的回答对你来说来晚了,但也许有人会觉得它有用。我需要同样的东西,所以我不得不写这个模板:

    <?php
    /*
    Template Name: Alphabetic
    */
    ?>
    
    
    <?php get_header(); ?>
    <div class="container">
    
        <div id="content" role="main">
        <h2 class="entry-title"><?php the_title(); ?></h2>                              
            <?php
    
            $my_wp_query = new WP_Query();
            $all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));
    
            $children = get_page_children($post->ID, $all_wp_pages);
    
            $letter="";
            foreach ($children as $child)
            {
                $first_letter=substr($child->post_title,0,1);
                if($letter != $first_letter)
                {
                    $alphabetic[]->post_title=$first_letter;
                    $letter=$first_letter;
                }
                $alphabetic[]=$child;
            }
    
            ?>
    
            <table style="border:none;">
                <tr>
    
                <?php
    
                $col = 4; //how many columns
    
                for($i = 0; $i < $col; $i++) {
    
                    echo '<td style="border:none;">';
    
                        $nr = (int)(sizeof($alphabetic)/4);
                        $i == $col - 1 ? $end = sizeof($alphabetic) : $end = $nr*($i+1);
    
                        for($j = $nr*$i; $j < $end; $j++) {
                            if(strlen($alphabetic[$j]->post_title)==1)
                                echo '<b>', $alphabetic[$j]->post_title, '</b><br />';
                            else
                                echo '<a href="'.get_permalink($alphabetic[$j]->ID).'">'.$alphabetic[$j]->post_title.'</a><br />';
                        }
    
                    echo '</td>';
    
                } ?>
    
                </tr>
            </table>
    
        </div><!-- #content -->
    </div><!-- #container -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-23
      • 1970-01-01
      • 1970-01-01
      • 2020-04-05
      • 1970-01-01
      • 1970-01-01
      • 2012-04-13
      • 2019-02-05
      相关资源
      最近更新 更多