Support » Fixing WordPress » How to get Post Title outside the loop

  • Resolved Jason_333

    (@jason_333)


    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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

    esmi

    (@esmi)

    Forum Moderator

    How about using wp_title() or single_post_title()?

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

    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?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to get Post Title outside the loop’ is closed to new replies.