Give help. Get help.

  • # September 8, 2009 at 11:46 am

    So, Chris has the new code snippets section, which is really cool. I have a question about this code though:

    < ?php $recent = new WP_Query("page_id=**ID**"); while($recent->have_posts()) : $recent->the_post();?>

    < ?php the_title(); ?>

    < ?php the_content(); ?>
    < ?php endwhile; ?>

    Is it possible to do the same thing based on the template used by the page you are trying to embed, rather than by its ID?

    # September 8, 2009 at 7:47 pm

    Hey Brent,

    When you say "page", do you actually mean "post"? That can make a huge difference.

    If you actually mean "post", it’s very simple, you just assign each post to a category and loop through that category.

    But, since you specifically mentioned "pages", let’s see what we can do with that… Off the top of my head, there’s no way to list pages by the template that they are using.

    Another question, what are you actually trying to accomplish here? Are you simply listing the pages, like this:

    Page One
    Page Two
    Page Three

    Or are you trying to display their content as well?

    Page One Title

    Page One content………….

    Page Two Title

    Page Two Content………….

    # September 9, 2009 at 1:17 pm

    Definitely ‘pages’ not ‘posts’.
    I need to display the content, not just their title.

    The thought process behind displaying them based on their templates was that I only need the content from pages that use a certain template. However, I sat and looked at it and I think that, with a bit of reorganizing, I would only need pages with a certain parent. So, that would be two different ways of filtering the pages that I need…If that makes sense.

    # September 9, 2009 at 1:55 pm

    If you’re only needing to loop through child pages of a specific parent, things will be much easier for you.

    # September 9, 2009 at 2:11 pm

    My thanks, but I need a bit more…How about getting all the children?
    This seems, to me, to require that you specify each child page and I’d like to have it get all of them.

    This code

    < ?php query_posts( 'post_parent' => 130
    ); // retrieve the child page of a parent

    Is not showing anything on my page.

    # September 9, 2009 at 2:55 pm
    < ?php query_posts(array('showposts' => 2, ‘post_parent’ => 130, ‘post_type’ => ‘page’)); ?>

    This seems to be working…Does that seem right?

    # September 9, 2009 at 3:17 pm

    Makes sense to me, just remember that the "2" there will make sure that only a maximum of two pages show.

    # September 9, 2009 at 3:50 pm

    Yeah, I’m still testing and configuring.

    Thanks for all your help.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.