ThemeShaper Forums » Thematic


CodeSnip4-u| List posts in certain category on any page.

(3 posts)
  • Started 2 years ago by mrmikeman
  • Latest reply from mrmikeman
  • This topic is not resolved
  1. mrmikeman

    I dont know if this code is easy to find or anything but I thought id post it anyways encase anyones looking

    this snippet will list all posts in a category which you specify on a page which you specify
    the code below will replace any content within that page with the list of Linked posts within the category you chose.

    function my_page_of_posts() {
    if (is_page('833')) {
    $custom_loop = new WP_Query('posts_per_page=5&cat=9');
    echo '<div class="my-archives"><ul class="archive-list">';
    if ( $custom_loop->have_posts() ) : while ( $custom_loop->have_posts() ) : $custom_loop->the_post();
    echo '<li><a class="archive-link" href="' . get_permalink() . '">' . get_the_title() . '</a> <span class="my-comment-count">( ';
    comments_number('0', '1', '%');
    echo ' )</span></li>';
    echo '</ul></div>';

    Make sure to edit the Numbers in the code above to correlate to your specific needs,
    Page to list links on, Category which to pull posts from, Number of posts to display in the list

    if you want to KEEP the content of the page you choose to display the list on, then change




    Snippets rock!

    Posted 2 years ago #
  2. mrmikeman

    that snippet will also include the Comment Count of each post to the right.

    if you dont want the comment count to show, just remove

    <span class="my-comment-count">( ';
    comments_number('0', '1', '%');
    echo ' )</span>

    from the snippet

    Posted 2 years ago #
  3. mrmikeman

    hm that seems to break the other pages on the site, hides the content... DOH!!

    anyone know why?

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.