WordPress.org

Ready to get started?Download WordPress

Forums

display subpages of a category (10 posts)

  1. dbarba
    Member
    Posted 7 years ago #

    I'm using a plugin (page_organizer) that assigns categories to pages.

    I have a page called product that is also in the category product.

    I have subpages of product (product 1, product 2, product 3).

    I want these subpages (title and content) to display on the Product page. In order, full story.

    How do I get the page to identify what category it is in and pull in all the subpages with the same category name?

  2. MichaelH
    Member
    Posted 7 years ago #

    Do you have a link to that plugin, please.

  3. dbarba
    Member
    Posted 7 years ago #

  4. MichaelH
    Member
    Posted 7 years ago #

    For that plugins options, do you have the box 'Use Page Specific Categories:' checked?

  5. dbarba
    Member
    Posted 7 years ago #

    Yes I do.

  6. MichaelH
    Member
    Posted 7 years ago #

    Is it sufficient to say the sub-pages you want displayed have a Page Parent called Product?

    If so, is it necessary to even involve the 'Page' categories?

  7. dbarba
    Member
    Posted 7 years ago #

    If it can be done without categories, that is fine with me. I'm just figure a way to have subpages act like posts. With the full stories being displayed one right bellow the other.

    I'm using subpages instead of posts because of my drop down menus. Also there are only a couple Parent/child pages I want to work like this, most the others will work in the typical fashion of clicking to a single page.

  8. MichaelH
    Member
    Posted 7 years ago #

    Assuming the Pages in question have a particular Parent page, and the post_id for that Parent page is 134 then you could use the example from Displaying_Posts_Using_a_Custom_Select_Query but use this as the $querystr

    $querystr = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_parent IN (134) AND $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'page' ORDER BY $wpdb->posts.post_date DESC";

    Of course, you will put this code in a Page Template and assign that page template to the Parent Page.

  9. mahalie
    Member
    Posted 6 years ago #

    Is there a way to extract the current post (page) ID from the existing querystring and then store it in new var so that you could create a generic template instead of manually specifying the page ID?

    (I don't know PHP very well yet)

  10. mahalie
    Member
    Posted 6 years ago #

    Btw, I created a page using the Codex instructions Displaying Posts using a Custom Select Query That would display the full posts of subpages for a page.

    Here's the code, if anyone's interested.

    <?php
    /*
    Template Name: Parent Page
    This page displays current page entry and the full posts of all subpage entries.
    It was created for use with documentation where you have outline-type docs with subsections.
    */
    ?>
    <?php get_header(); ?>
    
    	<div id="content" class="narrowcolumn">
    <?php if (have_posts()) : while (have_posts()) : the_post();
    ?>
    		<div class="post" id="post-<?php the_ID(); ?>">
    		<h2><?php the_title(); ?> </h2>
    		<?php edit_post_link('Edit', '<small>', '</small>'); ?>
    <?php
    
     $querystr = "SELECT wposts.* ".
        "FROM $wpdb->posts wposts ".
        "WHERE wposts.post_status = 'publish' ".
        "AND wposts.post_type = 'page' ".
    		"AND wposts.post_parent = '". $id ."' ".
        "ORDER BY wposts.menu_order ASC";
    
     $pageposts = $wpdb->get_results($querystr, OBJECT);
    
     ?>
     <?php if ($pageposts): ?>
     <?php foreach ($pageposts as $post): ?>
     <?php setup_postdata($post); ?>
    
     <div class="post" id="post-<?php the_ID(); ?>">
     <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
        <?php the_title(); ?></a></h3>
        <small><?php the_time('F jS, Y') ?> <?php edit_post_link('Edit', '', ''); ?><!-- by <?php the_author() ?> --></small>
        <div class="entry">
           <?php the_content('Read the rest of this entry ยป'); ?>
        </div>
     </div>
     <?php endforeach; ?>
     <?php else : ?>
        <h2 class="center">Not Found</h2>
        <p class="center">Sorry, but you are looking for something that isn't here.</p>
        <?php include (TEMPLATEPATH . "/searchform.php"); ?>
     <?php endif; ?>
    		</div>
    		<?php endwhile; endif; ?>
     	</div>
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic