Support » Themes and Templates » the_content() does not work

  • Resolved VirusZ



    I am currently developing a personal theme and I have run into some problems with the wordpress functions..

    Here is a part of my code that is giving me trouble:

    $posts = get_posts('numberposts=6&offset=0');
    foreach($posts as $post) :
    <li><a href="<?php the_permalink(); ?>" class="lista"><?php echo substr(get_the_title(), 0, 75); if(strlen(get_the_title()) > 75) echo '...';?></a> --- <?php the_content(); ?></li>
    <?php endforeach; ?>

    The function the_content() only outputs a <br /> in the html source. I have tried replacing the_content() with the_excerpt() and this works. I’m not sure why the_content() doesn’t work..
    I hope someone can explain me why this happens.

    Thank you!

Viewing 6 replies - 1 through 6 (of 6 total)
  • It seems like the_content can’t get at the post’s ID. This is usually stored in $id when the page is being viewed. See if echo $id; works at all.

    yes.. you are right
    the echo $id does not return anything..
    can the id be intialised in a certain way?
    I only need to show the latest post in a certain category
    I know the code I posted doesn’t do that but I would have modified it somehow if the_content() worked.

    There’s a WP function that gets the ID, I can’t remember its name though. It might be get_the_ID, search around on the codex it should turn up.

    There is one initialization function that you need to call inside the loop before calling all other template tags.

    foreach($posts as $post) :
    // the_content(), etc

    Thank you!
    That did the trick.
    The codex isn’t organised very good… I somehow missed the setup_postdata() function even though I browsed the codex back and forth..
    Thanks for the solution 😀

    Just found this solution – saved me from great frustration!

    I’m wondering – shouldn’t this page in the codex:

    …be updated to include that quite essential line of code?

    Would’ve saved me 15 minutes of grief…

    I’m still pretty new and figured I should ask before just going in there and making a change!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘the_content() does not work’ is closed to new replies.