ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    [How-To] Create Archives Page Automatically in Wordpress

    IT Discussion
    linux wordpress php
    1
    1
    786
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • thanksajdotcomT
      thanksajdotcom
      last edited by thanksajdotcom

      So I've been trying to find a way to create an archives page that lists all articles I've written on one page with the links. Before I was doing this manually, but I've been looking for a way to automate this. Well, I finally found it! Here is how you do this on Linux:

      Go into your site's root folder and navigate to /wp-content/themes/your_theme_here. For me, it's

      cd /var/www/thanksaj.com/wp-content/themes/yoko
      

      Next, create a copy of page.php and name it something you can remember. I did this:

      cp page.php all_pages_template.php
      vi all_pages_template.php
      

      Now that you're in vi, I did the following:

      My original page.php file looked like this:

      <?php
      /**
       * @package WordPress
       * @subpackage Yoko
       */
      
      get_header(); ?>
      
      <div id="wrap">
      <div id="main">
      
      		<div id="content">
      
      								<?php the_post(); ?>
      
      								<?php get_template_part( 'content', 'page' ); ?>
      
      								<?php comments_template( '', true ); ?>
      
      		</div><!-- end content -->
      
      <?php get_sidebar(); ?>
      <?php get_footer(); ?>
      

      I removed the first and second lines of php of the DIV content. After that, I inserted my own PHP, taken from here. My new php file looks like this:

      <?php
      /**
       * @package WordPress
       * @subpackage Yoko
       */
      
      get_header(); ?>
      <div id="wrap">
      <div id="main">
      
      		<div id="content">
      								<?php
      								/*
      								Template Name: All Posts
      								*/
      								?>
      								<?php
      								$debut = 0; //The first article to be displayed
      								?>
      								<?php while(have_posts()) : the_post(); ?>
      								<h2><?php the_title(); ?></h2>
      								<ul>
      								<?php
      								$myposts = get_posts('numberposts=-1&offset=$debut');
      								foreach($myposts as $post) :
      								?>
      								<li><?php the_time('D, M jS, Y') ?>: <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
      								<?php endforeach; ?>
      								</ul>
      								<?php endwhile; ?>
      
      								<?php comments_template( '', true ); ?>
      
      		</div><!-- end content -->
      
      <?php get_sidebar(); ?>
      <?php get_footer(); ?>
      

      You can make the "the_time" format anything you want. Follow the formatting found here.

      You can see the final results and what they look like here: http://www.thanksaj.com/archives/

      Personally, I like it, and now all my links are aggregated in one spot. Hope this helps someone else!

      Thanks,
      A.J.

      1 Reply Last reply Reply Quote 2
      • 1 / 1
      • First post
        Last post