• 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)
  • I believe you have to swap out the existing (default) code in the index.php file. Be careful you don’t strip out your styling divisions (classes and IDs).

    If you want to contact me offlist (check my profile), I can try to help you sort it out.

    Thread Starter essezeta

    (@essezeta)

    hi jonimueller…
    i did it…

    look at your email… i sent you my index.php

    than we can post solution…

    thank you for interest… ??
    hanslukas

    Thread Starter essezeta

    (@essezeta)

    here my code for index.php…
    look at comments
    thank averyone ??

    <?php get_header() ?>
    <div id="wrapper" class="index">
    <div id="content">
    
    		<!--post titlecustom query code
    		check for cmonth added by the monthly nav -->
    		<?php $cmonth = $_GET["cmonth"]; ?>
    		<?php 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"); ?>
    		<!--set a parameter i as 1
    		this helps to identify the first post -->
    		<?php $i=1 ?>
    		<!--loop starts -->
    		<?php 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; ?>
    
    <!-- COMMENT for jonimueller
    till here the script works...
    code below (navigation month by month) i can't see it on my page... why? can you find some error? -->
    
    		<!-- set values for the next and previous cmonth -->
    		<?php $cmonth_num_plus = $cmonth + 1; ?>
    		<?php $cmonth_num_minus = $cmonth - 1; ?>
    		<!--	set up a way to check the first day -->
    		<?php $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 -->
    		<?php $start_month = 5; ?>
    		<?php $start_year = 2008; ?>
    		<!--set the divider between the links -->
    		<?php $divider = ' | '; ?>
    		<!-- if the previous month exists display the 'previous' link -->
    		<?php if($current_year >= $start_year && $cmonth_check>$start_month){
    		echo '<a href="'.get_bloginfo('url').'/?cmonth=';
    		echo $cmonth_num_plus.'">&laquo; Previous Month</a>';
    		}
    		//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('https://localhost/ildiavoloa4').'/?cmonth=';
    		echo $cmonth_num_minus.'">Next Month &raquo;</a>';
    		} ?>
    
    </div><!-- #content -->
    </div><!-- #wrapper -->
    <?php get_sidebar() ?>
    <?php get_footer() ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘create a monthly navigation’ is closed to new replies.