• I’ve been blogging for about two years now with WordPress and my “Archives” list in my sidebar is getting rather long. How would I code it so that the Archives would only show, say, the last 4 months, and then had something like a “more…” link to the rest of the archives?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Alright, me matey, here’s what ya do. Look in the php of your archives page (usually archives.php) and look for the php code that tells the archives to appear. It should look like this:


    <?php wp_get_archives(); ?>

    It might, however, look like this:


    <?php wp_get_archives('some numbers or modifiers'):?>

    What you want to do is change (or add) the modifiers.

    For instance, you can do this to get the last 12 months:

    <?php wp_get_archives('type=monthly&limit=12'); ?>

    To do what you want, make it this:

    <?php wp_get_archives('type=monthly&limit=4'); ?>

    If you want to learn more about the Archive function, check it out on the codex:
    Here

    Hope that helps.

    Oh, and to answer your second question, I’d say to create a sub-page of the archives page that lists the archives with no limit, and link to it at the bottom of the archive page with html. Just my two cents.

    Thread Starter davez0r

    (@davez0r)

    Thanks, that’s what I’m going for. However, I’m probably missing something really simple (sorry, not very PHP knowledgable), but when I tried inserting the PHP code into a new page, WordPress formatted it as plain text. How do I get it to call the Get_Archives function correctly? The code I have pasted in the page is:

    <?php _e(‘Archives’); ?>

    <?php wp_get_archives(‘type=monthly&format=other&after=
    ‘); ?>

    When posted WordPress inserts a space right before the first “?” in each line.

    davez0r,

    The Page & Post works differently in WordPress. You can not simply create & insert PHP code into Page.

    <quote>create a sub-page of the archives page that lists the archives with no limit</quote>

    As monkeypup suggested above, all you have to do is:
    1. First create a Page template for e.g. copy your Archive.php template and save as Archive-2.php (name it, what you like). And open it using Notepad and insert the template name, you created.

    1a. Or simply create a new template and insert the following and save as Archive-2.php.

    <?php
    /*
    Template Name: Archive-2
    */

    <?php _e('Archives'); ?>

    <?php wp_get_archives('type=monthly&format=other&after=
    '); ?>
    ?>

    2. After this goto dashboard /Write/Page and create a new page.

    a. Enter the Page title like Full Archive List(or whatever you like).
    b. Click on Page template (located on the right side) and select the new template from the dropdown Archive-2.php (Created in step 1a)
    c. And save the new page. Remeber don’t put anything in the body part of the page.

    Thread Starter davez0r

    (@davez0r)

    After I create the page and load it in a browser I get this error:

    Parse error: syntax error, unexpected ‘<‘ in path/to/archivs.php on line 16

    line 16 is where I pasted in the above code.

    My whole template looks like this

    <?php /*
    Template Name: Archives
    */
    ?>

    <?php get_header(); ?>
    <?php get_sidebar(); ?>

    <div id="content">
    <div class="post">
    <?php
    /*
    Template Name: Archive-2
    */

    <?php _e('Archives'); ?>

    <?php wp_get_archives('type=monthly&format=other&after=
    '); ?>
    ?>
    </div>
    </div>

    <?php get_footer(); ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Abbreviated Archives?’ is closed to new replies.