create a monthly navigation
-
hi…
i need to create a monthly navigation, i found this solution…I tried to use it pasting the code on mi index.php, but don’t work…
where my error please? is not just copy and past the code?Look the code:
1 – create a query
here the codice:
//custom query code //check for cmonth added by the monthly nav $cmonth = $_GET["cmonth"]; if($cmonth==""){$cmonth = 0;} //get the month minus the offset of cmonth $current_month = date('m', strtotime($date.'-'.$cmonth . 'months' )); //get the year minus the offset of cmonth $current_year = date('Y', strtotime($date.'-'.$cmonth . 'months' )); //make the query query_posts("monthnum=$current_month&year=$current_year&order=DESC");
2 – Adding the current month
here the code:
//set a parameter i as 1 //this helps to identify the first post $i=1 //loop starts if (have_posts()) : while (have_posts()) : the_post(); ?> //display the month and year at the top of the page <?php if($i=='1'){echo ' <h1>'; the_time('F Y'); echo '</h1> ';} ?> <!--post title --> <h2><?php the_title(); ?></h2> //post content <?php the_content(__('Read more'));?> //increase i through the loop <?php $i++; ?> <?php endwhile; else: ?> <?php _e('Sorry, no posts matched your criteria.'); ?> //end the loop <?php endif; ?>
3 – the navigation…
here the code:
//set values for the next and previous cmonth $cmonth_num_plus = $cmonth + 1; $cmonth_num_minus = $cmonth - 1; //set up a way to check the first day $cmonth_check = $current_month-$cmonth; //set the date that your blog starts from //there should be no blog posts earlier than this date //in this example the start date is sept 2007 //the month is represented by a number $start_month = 8; $start_year = 2007; //set the divider between the links $divider = ' | '; //if the previous month exists display the 'previous' link if($current_year >= $start_year && $cmonth_check>$start_month){ echo '<a href="'.get_bloginfo('url').'/?cmonth='; echo $cmonth_num_plus.'">? Previous Month'; } //if there is a 'previous' and 'next' display the divider if($current_year >= $start_year && $cmonth_check>$start_month && $cmonth>0) {echo $divider;} //if its not the current month display the 'next' link if($cmonth>0){ echo '<a href="'.get_bloginfo('url').'/?cmonth='; echo $cmonth_num_minus.'">Next Month ?'; }
Sorry for my english, I thank you
regards
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘create a monthly navigation’ is closed to new replies.