• Problem:
    On the home.php page I am using get_posts in several places. The first use of it is grabbing the content of a category called Welcome. I know it is working because it is grabbing the correct title. However, when I use the_content or the_excerpt the content is not being displayed. A random <br /> is.

    What I have Tried:
    I have searched everywhere. Nothing.
    I have removed the the_content and the_excerpt. That removes the <br />.
    Changing the variable name for get_posts does not matter. (unless I did it wrong… ?? )

    Code:

    Here is the code:

    <?php
    $blogposts = get_posts('numberposts=1&category=3'); //Welcome Message
    foreach($blogposts as $welcome_post) :
    ?>
    <div class="post">
    <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h1>
    <div class="entry">
    <?php the_content(); ?>
    </div>
    </div>
    <?php endforeach;?>
Viewing 8 replies - 1 through 8 (of 8 total)
  • try this:

    <?php
    $posts = query_posts('cat=3,4,5,6,7,8&offset=1&showposts=5');
    foreach ($posts as $post) :
    ?>
    <div class="Box"><a href="<?php the_permalink(); ?>" title="<?php the_title() ?>"><?php the_title() ?></a><small><?php the_time('F jS, Y') ?></small></div>
    <?php
    endforeach;
    ?>

    change the cats and nr of posts. Done

    Thread Starter dave_merwin

    (@dave_merwin)

    Why would I do that? That doesn’t make any sense for what I want to do.

    just to check IF the loop is correct. that is what i would do, test a working code. if it works then your code is wrong.

    but it’s ur call.

    Thread Starter dave_merwin

    (@dave_merwin)

    the loop works. It is pulling the title from the correct post. I document that in my post. Unless I am missing what you are saying.

    hm…i just use ur loop in my post and guess what. same prob. so it’s ur loop i think. u must try it, otherwise u can’t solv ur prob.

    cheers

    Thread Starter dave_merwin

    (@dave_merwin)

    That is what I am getting at. I use the same loop several times in the page in different sections. Exactly the same. And this is the one place that it goes wrong. All your test will accomplish is knowing that a loop will work. It won’t address why this one is failing.

    but did u try my code to see if it works? the only thing i can think of is your “$welcome_post”.

    good luck!

    Thread Starter dave_merwin

    (@dave_merwin)

    It does not matter what the variable name is. As long as it doesn’t conflict with the wp. CHanging the variable name or changing the category does not matter. It IS querying the database. It is returning a result. The problem is with the_content. So, again, does anyone else have any ideas why it would render a random <br />?

    Lemme know.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Random <br /> Instead of Content when using get_posts’ is closed to new replies.