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
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
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.
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!
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>
Does this work:
<?php
$posts=get_posts('monthnum=06');
echo "<pre>"; print_r($posts); echo "</pre>";
?>
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?
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>";
?>
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!
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
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
felixkarlsson
Member
Posted 4 months ago #
Thanks a lot MichaelH, you're my hero :)