WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Include category archive in wp_list_pages() ? (4 posts)

  1. jcdesign
    Member
    Posted 8 years ago #

    Okay, it says very clearly in the Codex that Pages can NOT be associated with a category.

    Even if we say pretty please?

    Maybe I'm trying to push the astounding flexibility of WP a little too far. Or maybe someone can give me a different way to wrap my head around this for a solution, BUT:

    • I'm creating a web site for a client that uses WP as a Content Management System.
    • A good deal of information is set up in static Pages.
    • This is in large part for the purposes of permalinks, but due to other technical difficulties I can't use permalinks at the moment.
    • Nonetheless, it's very useful to have pages because they create hierarchy, which I use both in the side menu and for editing purposes behind the scenes.
    • Contained WITHIN that hierarchy, I would like to have 'News', which would contain, essentially, all of the POSTS on the site. (They can all have the category 'news')

      Why? Well:

      • News seems like it's part of 'About Us' in this case. I don't want to give it undue attention when most visitors to the site will probably need other information found in the various pages. News is only a small part of this site.
      • If I created a static list of pages just to incorporate this link, then my client can't update that list if they want/need to.

    I think that about sums it up. SO, is there a way to do EITHER of the following:

    1. Include a category listing (could maybe use wp_list_cats) in the middle of a list of pages using wp_list_pages()?
    2. Create a page template that pulls in either all the posts within a category, or just all posts in general?

    The author will now cross his fingers and make an offering to the WordPress gods.

  2. Kafkaesqui

    Posted 8 years ago #

    I'd go with 2 (1 might be accomplished, but would involve some amount of source hacking or a lot of custom code). Set up a custom Page template:

    http://codex.wordpress.org/Pages#Creating_your_own_Page_Templates

    Then initialize The Loop in it with query_posts():

    <?php query_posts('category_name=News&showposts=-1'); ?>

    You can limit the # of posts displayed by providing a different value to 'showposts' (-1 will display all posts), but keep in mind you would lack the ability to page through previous/next post listings.

  3. spencerp
    Member
    Posted 8 years ago #

    Thanks for that Kafkaesqui.. =) That might come in handy for a good sidebar addition later on.. =)

    spencerp

  4. jcdesign
    Member
    Posted 8 years ago #

    Astounding!

    I had already duplicated the Loop in a new template, and that's where I'd gotten stuck. I did just what you said—I replaced the <?php if (have_posts()) : ?> statement with the query_posts statement, then ripped out the else and endif at the end of the loop. Works like a charm.

    Thank you so much, you rock!

    I think this should be part of the Codex. Maybe I'll write a how-to.

Topic Closed

This topic has been closed to new replies.

About this Topic