Create a wordpress page with archives of a category

I’m a bit stumped on this one. I’d like to create a page that is an archive of all posts of a certain category – and show excerpts. However, Reading through the WordPress docs, they say a page cannot be a post or associated with categories.

So, I’m now wondering if this is possible or if there is a work around. I’d really like to put this on a page as I’d like to have a custom sidebar as well. Is this possible with a custom page template? Any other ways this can be done that I am not thinking of?

Read More

Thanks!

Related posts

Leave a Reply

2 comments

  1. You can add this function to functions.php and then you can call it from any page template.

    If you need to create a new page template for the sidebar.

    FTP, download page.php
    rename page.php to page-custom.php (custom can be anything, just make sure its page-whatever.php
    In the page-custom.php
    Replace the comments section with (Custom Template Name can be anything you want)

    /**
     * Template Name: Custom Template Name
     *
    */
    

    replace the loop in your new template with a call to get_posts_custom('catSlug');

    then add this to your functions.php

    if(!function_exists('get_posts_custom')){
    function get_posts_custom($catSlug){
    
        $args=array(
          'post_type' => 'post',
          'post_status' => 'publish',
          'category_name' => $catSlug,
          'ignore_sticky_posts'=> 1
          );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <article class="post">
        <time class="date"><?php the_time('m.d.y') ?></time>
        <p><strong><?php the_title(); ?></strong>
    
        <?php the_excerpt(); ?>
    
        </p>
        </article>
           <?php
          endwhile;
        }
    wp_reset_query();
    }
    }
    

    Reference http://codex.wordpress.org/Class_Reference/WP_Query

    I didn’t fully test the function, but I am using a modified version of the same code. Mine doesn’t filter on the category slug, so that may need tweaking, but I did test to make sure it didnt break functions.php

  2. Create a page, lipsum for example.
    Create a PHP file with the page-[the title].php, page-lipsum.php for this example.
    Write your loop in that file.
    FTP that file to the directory of your theme.
    When you go to the URL for that page, the results should be what you’re looking for.