• Resolved Diventare Creative

    (@wms-group)


    I have a blog feeding into a custom template using this code in the body:

    <?php while (have_posts()): the_post(); ?>
    <?php endwhile; ?>

    What would I have to add for it to read only one post from one specific blog?

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • MichaelH

    (@michaelh)

    Use the template tag, query_posts(), and the p=x argument.

    iridiax

    (@iridiax)

    Thread Starter Diventare Creative

    (@wms-group)

    Thanks Michael,

    Not sure I am familiar enough to figure that out myself, are there any examples?

    Thread Starter Diventare Creative

    (@wms-group)

    I think what I need to do is insert this snippet between my existing code to call from one category?

    So:

    <?php while (have_posts()): the_post(); ?>
    <?php endwhile; ?>

    would become

    <?php while (have_posts()): the_post(); ?>
    <?query_posts('cat=-3'); ?>
    <?php endwhile; ?>

    With the number 3 being replaced with my category name. Is this right?

    MichaelH

    (@michaelh)

    It would be more like:
    <?query_posts(‘cat=-3’); ?>

    <?php while (have_posts()): the_post(); ?>

    Thread Starter Diventare Creative

    (@wms-group)

    Thanks everyone, read the articles and used your code examples to accomplish what I needed!

    Here’s what my final code looks like:

    <div id="rightcol2">
        <p><img src="../images/tipsheader.gif" width="204" height="37"></p>
        <div class="item">
          <?php if (have_posts()) : ?>
          <?php $temp_query = $wp_query; ?>
          <?php query_posts('category_name=tips&amp;showposts=1'); ?>
          <?php while (have_posts()) : the_post(); ?>
          <small>
          <?php the_time('F jS, Y') ?>
          <!-- by <?php the_author() ?> -->
          </small>
          <div class="entry">
            <?php the_content('Read the rest of this entry &raquo;'); ?>
          </div>
        </div>
        <?php endwhile; ?>
        <?php else : ?>
        <?php endif; ?>
      </div>

    It shows one post from the category “tips”. Awesome!!!

    Just in case anyone cares, my head code reads like this:

    <?php define('WP_USE_THEMES', false); get_header(); ?>
    require('../wordpress/wp-blog-header.php');
    query_posts('showposts=1');
    ?>

    Thanks everyone!

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

The topic ‘Need direction on customizing code’ is closed to new replies.