WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to get Post Title outside the loop (5 posts)

  1. Jason_333
    Member
    Posted 4 years ago #

    I noticed <?php the_title(); ?> doesn't work outside the loop. What would be a good way of calling the post title outside the loop.

    Thanks.

  2. Web Hosting India
    Member
    Posted 4 years ago #

    dint get u exactly ...

    but try this

    <ul>
    		<?php
          $catposts = get_posts('numberposts=10&category=17');
          foreach($catposts as $post) :
       ?>
       <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
       <?php endforeach; ?>
    	</ul>

    you can use this for showing only titles of post from a partioular category...here 10 is the number of posts and 17 is the category id

  3. esmi
    Forum Moderator
    Posted 4 years ago #

    How about using wp_title() or single_post_title()?

  4. Jason_333
    Member
    Posted 4 years ago #

    Thanks guys, esmi: <?php single_post_title(); ?> did the trick. Thanks.

  5. jbbrwcky
    Member
    Posted 4 years ago #

    On the same subject, I have a bit of code that outputs a 'you are here' kind of thing, but it gets displayed before the loop.

    How do I get the single_post_title() for that post when the code generating it is before the loop?

Topic Closed

This topic has been closed to new replies.

About this Topic