Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • WordPress archive.php template pages

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 604
    Comment on it

    Hello dear reader's !
    Today we will discuss about archive.php template page. Archive page is the great way to bring together your all old content in one page. It allow you to list your monthly archives, category archives, tag archives, author archives, and anything you want to add. You can also display your old content into sidebar but if your content more then you will face a problem called " clutter ". To avoid clutter you can use custom archive page to display your old content, it also provides your users with an efficient way to browser through your older content.

    Below is an example of how your page-archive.php file would look like:

    <!--?php
    /*    
    * Template Name: Archives
    */
    get_header(); ?--> 
    
    <div id="primary"> 
    <div id="content" role="main"> 
    
    <h1 class="entry-title"><?php the_title(); ?></h1>
    <?php the_post(); the_content();  ?> 
    
    <!-- The main functions of our Archives.php template will go below here -->  
    
    <?php get_search_form(); ?>
    
    <h2>Archives by Month:</h2>
     <ul> 
    <?php wp_get_archives(); ?> 
    </ul> 
    
    <h2>Archives by Subject:</h2> 
    <ul> 
    <?php wp_list_categories(); ?> 
    </ul> 
    
    <!-- The main functions of our Archives.php template will go above here --> 
    
    </div><!-- #content --> 
    </div><!-- #primary -->
    
    <?php get_footer(); ?>
    

    Your archive page template is ready. Now you need to create a new custom archives page in WordPress. For this, Go to your WordPress admin panel and add a new page (Pages New). Now look at the meta boxes below the publish button on the right hand side of your screen. You should see a meta box called Page Attributes. Click on the second dropdown (Template) and select Archive Page and Publish the page.

    These are some code which you can use in your custom archive page.

    wp_get_archives Examples

    <?php wp_get_archives('type=daily&limit=30'); ?> <!--Displays the last 30 days of posts.--> 
    <?php wp_get_archives('type=postbypost&limit=20'); ?> <!--Displays the last 20 posts.-->
    <?php wp_get_archives('type=weekly'); ?> <!--Displays weekly archives.--> 
    <?php wp_get_archives('type=weekly&limit=12'); ?> <!--Displays 12 weekly archives.-->
    <?php wp_get_archives('show_post_count=1'); ?> <!--Displays monthly archives with post counts.--> 
    <?php wp_get_archives('type=yearly'); ?> <!--Displays yearly archives.--> 
    <?php wp_get_archives('type=alpha'); ?> <!-- Displays all posts alphabetically. --> 
    <?php wp_get_archives('type=postbypost'); ?>  <!-- Displays all posts by date. Newest posts are listed first. -->
    

    wp_get_archives pages Examples

    <?php wp_list_pages(); ?> <!-- List all pages and sub pages. -->
    <?php wp_list_pages('title_li='); ?> <!-- Display all pages and sub pages but no list title. -->
    <?php wp_list_pages('sort_column=post_date'); ?> <!-- Sort pages by the date they were created. -->
    <?php wp_list_pages('sort_column=post_modified'); ?> <!-- Sort pages by the date they were last modified. -->
    <?php wp_list_pages('include=2,4,6' ); ?> <!-- Only list the pages that you specify. -->
    <?php wp_list_pages('exclude=1,9' ); ?> <!-- Exclude certain pages from the list. -->
    <?php wp_list_pages('depth=1' ); ?> <!-- Only display the top level of pages. -->
    <?php wp_list_pages('depth=2' ); ?> <!-- Display pages and the first level of sub pages. -->
    

    wp_list_categories Examples

    <?php wp_get_archives('show_post_count=1'); ?> <!-- Show post count of categories. -->
    <?php wp_list_categories('title_li=Info'); ?> <!-- Change the name of the list title from 'Categories' to 'Info'. -->
    <?php wp_list_categories('hide_empty=0'); ?> <!-- Display empty categories in the category list. -->
    <?php wp_list_categories('exclude=2'); ?> <!-- Do not list category 2. -->
    <?php wp_list_categories('depth=1'); ?> <!-- Show only top level categories. -->
    <?php wp_list_categories('depth=3'); ?> <!-- Show three level of categories (top category, child category and child of child category). -->
    <?php wp_list_categories('child_of=3'); ?> <!-- Only show the children categories of category 3 -->
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: