WordPress.org

Ready to get started?Download WordPress

Forums

Template - A-Z of Child Pages - Including 'A', 'B' etc.. (1 post)

  1. bunchofapes
    Member
    Posted 4 months ago #

    Hello all

    I am trying to figure this out, I can get in a list of child pages via php but I need to display what letter they are under and be able to pop a div around it to style the letter..

    See http://www.bee-craft.com/beekeeping-information-centre/ for the kind of thing I am working on..

    Any help appreciated! BTW the code im using isnt woking alphabetically, so if thats easier to sort, here it is:

    <div id="content" role="main">
    
            <?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;
            }
    
            ?>
    
                <?php
    
                $col = 3; //how many columns
    
                for($i = 0; $i < $col; $i++) {
    
                        $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 '<div class="BIClettertitle"><b>', $alphabetic[$j]->post_title, '</b></div><br />';
                            else
                                echo '<div class="BICletterlink"><a href="'.get_permalink($alphabetic[$j]->ID).'">'.$alphabetic[$j]->post_title.'</a></div><br />';
                        }

Reply

You must log in to post.

About this Topic