Forums

[resolved] Month archive - HELP PLEASE! (14 posts)

  1. felixkarlsson
    Member
    Posted 4 months ago #

    Hello!
    I've spend countless of hours to create a month archive that doesn't involve year in any way. When you click "June" for example, I want to show every single post from June, no matter what year it's from.

    I don't know if this is much of a problem for you guys, but I have apparently not figured it out so far.

    Any ideas?
    Thank you

  2. MichaelH
    moderator
    Posted 4 months ago #

    When you click "June" for example

    Don't know how that link is being presented but this will return all June posts:

    $june_posts=get_posts('monthnum=06');

    See query_posts Time Parameters

  3. felixkarlsson
    Member
    Posted 4 months ago #

    Thanks a lot!
    But as you said there's no link to it. I tried to make my own:
    <a href="<?php bloginfo('template_directory'); ?>/archive.php?m=01" title="Januar">Januar</a>

    The thing is, how can I use the functions, there's just an error message:
    Fatal error: Call to undefined function .. etc.

    Do I have to include something? I've tried to paste all lines in header.php without success.

  4. MichaelH
    moderator
    Posted 4 months ago #

    Example on my test system:

    http://localhost/wordpress/?monthnum=6

  5. felixkarlsson
    Member
    Posted 4 months ago #

    Okey, but does it work proper immediately?
    Don't you have to edit index.php?
    Anyway, it doesn't work for me.
    I've tried this code in index.php in my template folder:

    <?php
    if(isset($_GET["monthnum"])) {
    $month = $_GET["monthnum"];
    $query_posts('monthnum=$month');
    echo query_posts('monthnum=$month');
    }
    ?>

    Thank you, again!

  6. felixkarlsson
    Member
    Posted 4 months ago #

    You might have to know this as well. My link is:
    <a href="<?php bloginfo('url'); ?>/?monthnum=03" title="March">March</a></li>

  7. MichaelH
    moderator
    Posted 4 months ago #

    Does this work:

    <?php
    $posts=get_posts('monthnum=06');
    echo "<pre>"; print_r($posts); echo "</pre>";
    ?>
  8. felixkarlsson
    Member
    Posted 4 months ago #

    No, doesn't work :S Do you mean that I should put it in index.php in my template folder? I tried that...

    Doesn't anybody have a plugin, or finished code for this?

  9. MichaelH
    moderator
    Posted 4 months ago #

    Switch to the WordPress Default theme, deactivate all plugins, change permalinks to the Default, put this in wp-content/themes/default/index.php just before <?php if (have_posts()) : ?>

    <?php
    $posts=get_posts('monthnum=06');
    echo "<pre>"; print_r($posts); echo "</pre>";
    ?>
  10. felixkarlsson
    Member
    Posted 4 months ago #

    Array
    (
        [0] => stdClass Object
            (
                [ID] => 5
                [post_author] => 1
                [post_date] => 2009-06-13 12:28:40
                [post_date_gmt] => 2009-06-13 10:28:40
                [post_content] => Testar lite shit här! text osv...
    
    [caption id="attachment_6" align="alignright" width="249" caption="GIBK"]GIBK[/caption]
    
    Yes, lite text... bla bla
                [post_title] => Nytt inlägg
                [post_category] => 0
                [post_excerpt] =>
                [post_status] => publish
                [comment_status] => open
                [ping_status] => open
                [post_password] =>
                [post_name] => nytt-inlagg
                [to_ping] =>
                [pinged] =>
                [post_modified] => 2009-06-13 12:28:40
                [post_modified_gmt] => 2009-06-13 10:28:40
                [post_content_filtered] =>
                [post_parent] => 0
                [guid] => http://localhost/jobb/GumpaLalla/wordpress/wordpress/?p=5
                [menu_order] => 0
                [post_type] => post
                [post_mime_type] =>
                [comment_count] => 1
            )
    
        [1] => stdClass Object
            (
                [ID] => 4
                [post_author] => 1
                [post_date] => 2009-06-10 18:33:53
                [post_date_gmt] => 2009-06-10 16:33:53
                [post_content] => Hej hej, hemskt mycket hej :)
                [post_title] => Testar
                [post_category] => 0
                [post_excerpt] =>
                [post_status] => publish
                [comment_status] => open
                [ping_status] => open
                [post_password] =>
                [post_name] => testar
                [to_ping] =>
                [pinged] =>
                [post_modified] => 2009-06-10 18:33:53
                [post_modified_gmt] => 2009-06-10 16:33:53
                [post_content_filtered] =>
                [post_parent] => 0
                [guid] => http://localhost/jobb/GumpaLalla/wordpress/wordpress/?p=4
                [menu_order] => 0
                [post_type] => post
                [post_mime_type] =>
                [comment_count] => 2
            )
    
    )

    That's the result.

    How do I display it proberly?

    Thanks a lot!

  11. felixkarlsson
    Member
    Posted 4 months ago #

    And why doesn't this work:

    <?php
    // Link: /?p=archive&monthnum=06
    if($_GET["p"] == "archive") {
    $month = $_GET["monthnum"];
    $posts=get_posts('monthnum='.$month);
    echo "<pre>"; print_r($posts); echo "</pre>";
    }
    ?>

    The result is a white page with the text "array"
    Getting freaked out, need to get this done as soon as possible.

    Help please :D

  12. MichaelH
    moderator
    Posted 4 months ago #

    How do I display it proberly?

    Use a loop. Examples:
    http://www.daobydesign.com/blog/2007/07/modifying-wordpress-front-page/

  13. MichaelH
    moderator
    Posted 4 months ago #

    Using the WordPress Default theme in the archive.php this works fine for me:

    <?php
    // link http://localhost/wordpress/?monthnum=6
    $month=get_query_var('monthnum');
    echo 'month' .$month;
    ?>

    Also directing you to Custom_Queries

  14. felixkarlsson
    Member
    Posted 4 months ago #

    Thanks a lot MichaelH, you're my hero :)

Reply

You must log in to post.

About this Topic