• Resolved HorrorUK

    (@horroruk)


    I’m having trouble getting the title to show up on my theme.

    I’m using the following, which works ok on its own:

    <h1><?php the_title(); ?></h1>
    <div style="clear: both;"></div>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php the_content(__('Keep Reading'));?>
    <?php endwhile; else: ?>
    <?php endif; ?>

    I’ve got this code in a separate column:

    <?php $my_query = new WP_Query("showposts=2&cat=9&offset=0"); ?> <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php the_excerpt(); ?><?php endwhile; ?>

    I’ve narrowed down the problem to the following section of the above code:

    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>

    But I can’t figure out why it’s a problem.

    The following page is called ‘Video’, but it is showing the default WP page:

    http://ioaf.moonworks.co/video

Viewing 2 replies - 1 through 2 (of 2 total)
  • Are you resetting the query between your two loops? i.e. are you calling:

    <?php wp_reset_query(); ?>

    Also, in your custom query loop, does the following work?

    <?php echo $post->post_title; ?>

    If so, then the problem is that you’re not setting up the $post data, which you would do by adding this:

    <?php setup_postdata(); ?>

    This call would go somewhere here:

    <?php $my_query = new WP_Query("showposts=2&cat=9&offset=0"); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
         <?php setup_postdata(); ?>
         <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
         <?php the_excerpt(); ?>
    <?php endwhile; ?>

    Thread Starter HorrorUK

    (@horroruk)

    Thank you Chip, once again, you have come to my rescue.

    Adding the reset sorted out the problem.

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

The topic ‘Code is causing wrong title to appear’ is closed to new replies.