Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm building my first fully custom wordpress theme, and I'm starting to pull hairs out while trying to write the dynamic footer code! I've tried a bunch of codex this and codex that but can't seem to get the right results dynamically. That said, I've coded it manually to give you a preview of the structure I'm looking for, in hopes that you all can help me fix my mess.

Here goes...

<div class="footercat">
<h2><a href="http://domain.com/parent1/">Parent1</a></h2>
<ul>
    <li><a href="http://domain.com/parent1/child1/">Child1</a></li>
    <li><a href="http://domain.com/parent1/child2/">Child2</a></li>
    <li><a href="http://domain.com/parent1/child3/">Child3</a></li>
    <li><a href="http://domain.com/parent1/child4/">Child4</a</li>
    <li><a href="http://domain.com/parent1/child5/">Child5</a></li>
</ul>
</div>
<div class="footercat">
<h2><a href="http://domain.com/parent2/">Parent2</a></h2>
<ul>
    <li><a href="http://domain.com/parent2/child1/">Child1</a></li>
    <li><a href="http://domain.com/parent2/child2/">Child2</a></li>
    <li><a href="http://domain.com/parent2/child3/">Child3</a></li>
    <li><a href="http://domain.com/parent2/child4/">Child4</a</li>
    <li><a href="http://domain.com/parent2/child5/">Child5</a></li>
</ul>
</div>
<div class="footercat">
<h2><a href="http://domain.com/blog/">Blog</a></h2>
<ul>
    <li><a href="http://domain.com/category/category1/">Category1</a></li>
    <ul>
        <li><a href="http://domain.com/category1/recentpost1">Recent Post</a></li>
        <li><a href="http://domain.com/category1/recentpost2">Recent Post 2</a></li>
        <li><a href="http://domain.com/category1/recentpost3">Recent Post 3</a></li>
    </ul>
    <li><a href="http://domain.com/category/category2/">Category2</a></li>
    <ul>
        <li><a href="http://domain.com/category2/recentpost1">Recent Post</a></li>
        <li><a href="http://domain.com/category2/recentpost2">Recent Post 2</a></li>
        <li><a href="http://domain.com/category2/recentpost3">Recent Post 3</a></li>
    </ul>
</ul>
</div>

It's a pretty logical structure:

Parent1
    Child1
    ...
    Child5
Parent2
    Child1
    ...
    Child5
Blog
    Category1
        Recent Post1
        Recent Post2
    Category2
        Recent Post1
        Recent Post2

Parent1 and Parent2 are "Pages"; when on them, their top navigation shows as follows:

Parent1 | Child1 | Child2 | Child3 | Child4 | Child5

... as if they were on a child page titled Parent1. When they are on the Parent1 page, the url is: example.com/parent1, when they are on the child1 of parent1, the url is example.com/parent1/child1.

The page IDs of the parents are '14' and '19' in that order. And Child1-5 are the only children of their parent (ie: both 14 and 19 have their own child1-5).

share|improve this question
1  
What are parent1 and parent2? Are they the only parents? If not, how do you choose just those two? Are the categories all your categories? If not, how do you choose those two? –  Charles Clarkson Jun 4 '13 at 3:08
    
The home page is the parent to all the pages, other than that, there are 3 subpages: Parent1, Parent2, and Blog. Parent 1 and 2 have 5 childpages. The Blog has two categories and the client wanted to show the two most recent posts of each category. –  beta208 Jun 5 '13 at 13:18
    
That does not answer my questions. It just restates what you already said. We need more information. –  Charles Clarkson Jun 5 '13 at 13:22
    
Parent1 and Parent2 are pages; when on them, their top navigation shows as follows: Parent1•Child1•Child2•Child3•Child4•Child5, as if they were on a child page titled Parent1. Does this clarify? When they are on the Parent1 page, the url is: example.com/parent1, when they are on the child1 or parent1, the url is example.com/parent1/child1 –  beta208 Jun 5 '13 at 13:29
    
Yes. Thank you. What are the page IDs of Parent1 and Parent2? Are Child1 through Child5 the only children of the parent or only the first five child pages? –  Charles Clarkson Jun 5 '13 at 13:34

1 Answer 1

up vote 0 down vote accepted

I tested this as a function. You can place it in your footer or functions.php theme file and call it in your themes footer section. See the comments for links to the functions used.

function wpse_101774_footer() {

    // Start this part of footer on new line.
    echo "\n";

    foreach ( array( 14, 19 ) as $page_id ) {

        // Start .footercat div.
        echo "<div class='footercat'>\n";

        // Print the Parent post anchor markup.
        // See: http://codex.wordpress.org/Function_Reference/get_permalink
        // See: http://codex.wordpress.org/Function_Reference/get_the_title
        printf( '<h2><a href="%s">%s</a></h2>', get_permalink( $page_id ), get_the_title( $page_id ) );

        echo '<ul>';

        // List the child pages.
        // See: http://codex.wordpress.org/Function_Reference/wp_list_pages
        wp_list_pages( array(
            'depth'       => 1,
            'child_of'    => $page_id,
            'post_type'   => 'page',
            'post_status' => 'publish',
            'title_li'    => '',
        ) );
        echo '</ul>';

        // End .footercat div.
        echo "\n</div><!-- end .footercat -->\n";
    }

    $blog_post_id = 3081;

    // Print the Blog page anchor markup.
    // See: http://codex.wordpress.org/Function_Reference/get_permalink
    // See: http://codex.wordpress.org/Function_Reference/get_the_title
    printf( '<h2><a href="%s">%s</a></h2>', get_permalink( $blog_post_id ), get_the_title( $blog_post_id ) );

    // Start .footercat div.
    echo "<div class='footercat'>\n";

    echo '<ul>';

    // Add comma separated list of ctegory IDs in place of "1" (For example, 1, 45, 6 ).
    foreach ( array( 1 ) as $category_id ) {

        // Get the category object for this category ID.
        // See: http://codex.wordpress.org/Function_Reference/get_category
        $category = get_category( $category_id );

        // Get this category's posts.
        // See: http://codex.wordpress.org/Function_Reference/get_posts
        $posts = get_posts( array(
            'posts_per_page'  => 5,
            'category'        => $category_id,
            'post_type'       => 'post',
            'post_status'     => 'publish',
            'suppress_filters' => true
        ) );

        $post_anchors = '';
        if ( $posts ) {
            $post_anchors = '<ul>';
            foreach ( $posts as $post ) {

                // Print this category's posts.
                // See: http://codex.wordpress.org/Function_Reference/get_permalink
                // See: http://codex.wordpress.org/Function_Reference/get_the_title
                $post_anchors .= sprintf(
                    '<li><a href="%s">%s</a></li>',
                    get_permalink( $post->ID ),
                    get_the_title( $post->ID )
                );
            }
            $post_anchors .= '</ul>';
        }

        // Print this category's anchor and post anchors, if any.
        // See: http://codex.wordpress.org/Function_Reference/get_category_link
        printf( '<li><a href="%s">%s</a>%s</li>', get_category_link( $category_id ), $category->name, $post_anchors );

    }
    echo '</ul>';

    // End .footercat div.
    echo "\n</div><!-- end .footercat -->\n";
}
share|improve this answer
    
I will have to check this out. Thank you. If it works I will mark it as solved. –  beta208 Jun 6 '13 at 20:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.