Thursday, January 1, 2009

List all titles of WordPress posts in one page

Using this code, you can list all titles of WordPress posts in one page. An example of usage is in an Archives page.


<ul>
<?php
    global $post;
    $myposts = get_posts('numberposts=-1&offset=1');
    foreach($myposts as $post) :
?>
<li>
    <a href="<?php the_permalink(); ?>">
    <?php the_title(); ?>
    </a>
</li>
<?php endforeach; ?>
</ul>

You can change it to n number of posts, by changing -1 in "numberposts=-1" to n.
For tutorial on how to create an Archives page, please read this article.

8 comments :

  1. nie tuk wat ape yerk? arkib ker?

    <abbr>amans last blog post..Sumber Terbuka dan Linux Sepanjang 2008</abbr>

    ReplyDelete
  2. those codes shud be paste into a page rite ?

    <abbr>KNizams last blog post..Dah Bayar Zakat For 2008 Ke ?</abbr>

    ReplyDelete
  3. @aman, @Hanep: Untuk apa sahaja. Boleh juga digunakan untuk front page.

    @KNizam: Untuk arkib, bina template arkib dan paste kod tersebut. Kemudian bina page dengan template arkib sebagai default template.

    ReplyDelete
  4. camner nak buat archive tu eh ?

    <abbr>KNizams last blog post..Salam Tahun Baru 2009 !</abbr>

    ReplyDelete
  5. [...] Now, you already have an archives page by month and by subject/category. By the way, you could also have the archives page to display some or all posts title, as discussed in this article. [...]

    ReplyDelete
  6. [...] on a recent post in the sidebar or next page at the bottom of the website. I’d like to see a list all titles of articles in one page. Actually, I want to see that implemented on all self hosted wordpress based [...]

    ReplyDelete
  7. Thanks man - that's exactly what I was looking for :) It works 100% fine with WordPress 2.9.2 if anyone need to know (I'm writing this because release date of this post is end of 2008).

    ReplyDelete