WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] query posts -- formatting issue on page (2 posts)

  1. csleh
    Member
    Posted 6 years ago #

    I am trying to pull posts into a page. Have tried many different ways, but when it does work it seems to be pulling in the formatting of the single post template along with the data.
    This is what I am currently using on the page template:

    <?php
       if (is_page('our-team')) {
          query_posts("cat=12");
       }
    ?>

    But instead of pulling in the content and showing in the div, it is pulling in extra divs, just like from the single post template.

    I have tried using an INCLUDEPATH, but if I first query the posts in the page template, I get 2 copies of every post. If I query the category within the team.php template, I get two copies of every post. One copy will be formatted correctly, the other will have the additional info from the single post template.
    The "team.php" template contains only:

    <?php while (have_posts()) : the_post(); ?>
    <h1><?php the_title(); ?></h1>
    		<?php the_content(''); ?>
      <?php endwhile;?>

    How can I pull in post DATA, without also bringing in the single post template?
    (and I cannot change the single post template, since many pages use that.)

  2. csleh
    Member
    Posted 6 years ago #

    This seems to be working:

    <?php
       if (is_page('our-team'))  { ?>
    <?php $temp_query = $wp_query; ?>
    <?php query_posts('cat=12'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <h3><?php the_title(); ?></h3>
    <p><?php the_content(); ?></p>
    <?php endwhile; ?>
     <?php }
    ?>

    I believe the first two and last two lines are saying "if this is the our team page, do this stuff"
    The stuff in the middle is a temporary query, which doesn't affect the main page content (ie no doubling of "the_content", but two distinct contents). the endwhile is saying my temporary query is finished.

    If my above translation is incorrect please say so, I'm trying to learn.

    FYI -- this code goes after the closing of the loop on the page.

Topic Closed

This topic has been closed to new replies.

About this Topic