Support » Fixing WordPress » Help creating a category archive (or child page archive)

  • Hi,

    On my website I need to create a page (or post) for each of my collaborators, that will have their photo and bio, etc. Then I’d like to create a template page that will automatically list these posts/pages (alphabetical ascending order by post/page title) with a thumbnail and link to the actual page.

    I tried using a Page hierarchy like this:

    Collaborators (parent)
    — John doe (child)
    — Jane doe (child)

    etc.

    It works great to do this and then use wp_list_pages on my archive page to pull up the list of child pages.

    <div class="archive">
    
    					<strong><?php _e("Collaborators"); ?>:</strong>
    						<ul>
    							<?php wp_list_pages('child_of=117&title_li='); ?>
    						</ul>
    
    				</div>

    But I can’t find a way to include thumbnails or create excerpts.

    So I’m thinking maybe it’s better to use normal posts for each collaborator, and assign all the collaborator posts to a specific category. Then create a category archive page that will list them all.

    It sounds really complicated, but it’s actually not. I’ve Googled and tried many different things, and nothing has worked well at all. I’m totally frustrated now, need a hug, and hope someone can help me out with this before I go crazy.

    Should I do this with posts or pages? And would anyone be willing to help me figure out the code?

    Thanks ever so much in advance — if I get a good solution to this on my own I will post it here, as I’ve seen lots of other people with similar questions that haven’t been resolved.

    Cheers,
    L

Viewing 7 replies - 1 through 7 (of 7 total)
  • Using either the child pages or a category should work. The code for the template would be almost identical. For the child page approach, your query should be similar to this:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
       'posts_per_page' => 10,
       'paged' => $paged,
       'caller_get_posts' => 1,
       'post_type' => 'page',
       'post_parent' =>  45,  // The ID of the parent page
       'orderby' => 'title',
       'order' => 'ASC'
    );
    query_posts($args);
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
       'posts_per_page' => 10,
       'paged' => $paged,
       'caller_get_posts' => 1,
       'cat' => 65, // The category id for collaborator
       'orderby' => 'title',
       'order' => 'ASC'
    );
    query_posts($args);

    Otherwise the code should be the same for the loop.

    Thread Starter Lori

    (@delphine)

    Hi, and thanks so much for the advice!

    I’m a bit confused still, so I hope you (or others here) won’t mind a follow-up:

    If we say that I commit to the “page” approach, would this first template code go in the template for the parent page or for each child page?

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
       'posts_per_page' => 10,
       'paged' => $paged,
       'caller_get_posts' => 1,
       'post_type' => 'page',
       'post_parent' =>  45,  // The ID of the parent page
       'orderby' => 'title',
       'order' => 'ASC'
    );
    query_posts($args)

    The code is for the template used by the parent page. It shows all the children on the parent page.

    The parent page will be in your menu and when someone clicks on it, it will bring up the screen with the children.

    I believe that I wish to use the page code above. I opened the default template in 20-10 and don’t see where I would place this query. Sorry to be dense on this one.

    Please don’t apologize – everyone has to start from the beginning to learn.

    Make a copy of page.php. Name it collaborators.php. Then make it into a custom template by replacing this:

    <?php
    /**
     * The template for displaying all pages.
     *
     * This is the template that displays all pages by default.
     * Please note that this is the WordPress construct of pages
     * and that other 'pages' on your WordPress site will use a
     * different template.
     *
     * @package WordPress
     * @subpackage Twenty_Ten
     * @since Twenty Ten 1.0
     */

    with this:

    <?php
    /**
    Template Name: Collaborators
    */

    Then, insert this code for the query just before the line that starts with <?php if ( have_posts() ):

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
       'posts_per_page' => 10,
       'paged' => $paged,
       'caller_get_posts' => 1,
       'post_type' => 'page',
       'post_parent' =>  $post->ID,  // The ID of the parent page
       'orderby' => 'title',
       'order' => 'ASC'
    );
    query_posts($args);
    ?>

    You will also need to replace the line <?php the_content(); ?> with whatever you want to show for each collaborator.

    Save the file, create a Page for Collaborators and assign it this new template. Put your new page in your menu and take it for a test.

    EDIT: I should also mention that it would be best if you created a child theme instead of modifying Twenty Ten itself. If you don’t, all your changes will be lost the nest time TT is updated. Here is a tutorial on creating a Child theme.

    Most helpful and I thank you for your understanding that my denseness may not be genetic, but lack of familiarity with this conceptually 😉

    I wondered about the effect of an update — so it will overwrite custom pages I added? I wondered if, since it is something added, it would leave it untouched while updating everything around it.

    I have been using child themes with limited understanding (my favorite thus far has been thirty-ten with three columns). I learned the hard way that twenty ten updates wiped out changes 🙂 but I thought perhaps that was limited to situations where I modified the existing files and would not be affected when I added a new template.

    What I want is to use this template for is maybe four parent pages that actually do not exist so that they simply list the child pages title as a link.

    Can I do this with one template?

    Off shoot question: how difficult to always add links at bottom of each page to all child pages of it?

    Lots of questions in one post, but I’ll try to answer without being too long-winded.

    First, about the updates. Anything in your theme folder is liable to be lost on an update. The actual content of pages added through the Admin panel go to the database. Those will not be touched. Any .php files you add to the theme folder will go.

    Second, the code I provided will display the children of the calling page. So it can be used for any parent page and will display the children of that page.

    Third, I am not quite sure I understand the question, but here is what I think you wanted to know. If you add more children to a parent page, they will automatically show up on the page. They will not be at the bottom since children are sorted in order by title.

    Hope that helps.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Help creating a category archive (or child page archive)’ is closed to new replies.