• Resolved dla4422

    (@dla4422)


    I’d like to create a page template that uses a category to display the same information (post) in a hero space, while the content beneath changes.

    Example: Every product page has the same hero space, same text, same image. But each product needs to different information below the hero space.

    I tried adding this code in a hero space div above the main loop on my page template.

    ` <?php query_posts(‘cat=10’); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <h1><?php the_title(); ?></h1>
    <div id=”post-<?php the_ID(); ?>” <?php if(function_exists(‘post_class’)) : post_class(); else : echo ‘class=”post”‘; endif; ?>>

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

    I know I can use query_posts below the above code to call the page id I want for a specific product page. But i need for people to add more product pages without editing the template every time.

Viewing 7 replies - 1 through 7 (of 7 total)
  • What about using a Custom Field — for each page, add a custom field that represents the category you want displayed with that page.

    Thread Starter dla4422

    (@dla4422)

    Looks promising. Thanks.

    Thread Starter dla4422

    (@dla4422)

    Any idea how I can use custom fields to show only the most recent post from a specific category outside the loop?

    Not sure what you mean by “use custom fields to show only the recent post”, but you likely would use the template tag, query_posts(), which has category and custom field arguments that you might find useful.

    Thread Starter dla4422

    (@dla4422)

    If I were to use query_posts() to show a specific post outside of the main loop, I would need to include it in a separate loop. Does using custom fields eliminate the need to have a second loop? Can I just use the template tag?

    I tried using query_posts in a custom field to call one post from a category once inside of a second loop, once with just the template tag. Nothing showed up with either method. Should one of these methods work? If so, I’m sure there’s something wrong in my code.

    FYI, here’s what I’m working on http://derekwrites.com/ican/?page_id=17.

    Currently I’m using a custom field to pull in the copy in the hero space–just html. I’m trying to make it so that when the client writes a post categorized “services-banner” it automatically updates this area. All I want to do is use a custom field to show the post in that hero space. Suggestions…

    Sorry if this is confusing. But, thanks for your help. Much appreciated. Sorry if I’m not doing a very good job of explaining.

    I believe you would want additional loops.

    I think this article might help clarify the 2nd loop questions:

    http://www.daobydesign.com/blog/2007/07/modifying-wordpress-front-page/

    Note that get_posts can use the same arguments as query_posts.

    Thread Starter dla4422

    (@dla4422)

    found this plugin http://guff.szub.net/2005/01/27/get-a-post/
    Did exactly what I was trying (not well) to describe. Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Adding query_post to static page template’ is closed to new replies.