localendar Forums Homepage

Print at Apr 26, 2024, 3:41:32 PM View all posts in this thread on one page
Posted by n1lykme at Jan 10, 2013, 1:15:50 PM
Show next month
The script for the dynamic calendar is messing with the menu on my responsive wordpress site and making it not work when I go mobile. Works fine in regular view. So as a solution I was thinking of creating distinct static pages on my webpage I'll just create links to. Was wondering if there is a way to write the query to be Month+1, Month+2.... with "Month" representing the current month calendar so I don't have to manually change links every month?
Thanks.

Posted by support at Jan 13, 2013, 5:30:23 PM
Re: Show next month
We do dynamic month substitution in the title:
http://www.localendar.com/docs/display/lc/Dynamic+replacement+of+month+name+or+number

However, if I understand you correctly, you want links that automatically go to the current month, next month, etc.

The easy part is: The calendar always defaults to the current month. So
http://www.localendar.com/public/n1lykme will always be "this month"

I think you can get what you want using our "start_date" parameter(http://www.localendar.com/docs/display/lc/Your+Calendar%27s+URL+and+Parameters), a little JavaScript and Date arithmetic. Hopefully this is close enough to get you started:

<a href='http://www.localendar.com/public/n1lykme'>This Month</a><br/>
<script>
function getNextCalendarMonth(in_date)
{
if (in_date.getMonth() == 11) {
var out_date = new Date(in_date.getFullYear() + 1, 0, 1);
} else {
var out_date= new Date(in_date.getFullYear(), in_date.getMonth() + 1, 1);
}
return out_date;
}
function formatDate(in_date)
{
var out_string = "";
out_string = (in_date.getMonth()+1)+"/"+in_date.getDate()+"/"+in_date.getFullYear();
return out_string;
}

var mplus1=getNextCalendarMonth(new Date());
var mplus2=getNextCalendarMonth(mplus1);
var mplus3=getNextCalendarMonth(mplus2);
var mplus4=getNextCalendarMonth(mplus3);
document.write("<a href='http://www.localendar.com/public/n1lykme?start_date="+formatDate(mplus1)+"'>This Month+1</a><br/>");
document.write("<a href='http://www.localendar.com/public/n1lykme?start_date="+formatDate(mplus2)+"'>This Month+2</a><br/>");
document.write("<a href='http://www.localendar.com/public/n1lykme?start_date="+formatDate(mplus3)+"'>This Month+3</a><br/>");
document.write("<a href='http://www.localendar.com/public/n1lykme?start_date="+formatDate(mplus4)+"'>This Month+4</a><br/>");
</script>


whoa.. too much free time today wink
----------------------------------------
Marc Higgins
Support Associate, localendar.com
Follow us on Twitter! http://www.twitter.com/localendar_news

Posted by support at Jan 13, 2013, 5:35:57 PM
Re: Show next month
I don't like the look of "Month+1, Month+2, etc"
I mean, if you really want to be "responsive", we should show the proper month names for the period. So here's the "extra-credit" version that handles that:

<a href='http://www.localendar.com/public/n1lykme'>This Month</a><br/>
<script>

var month_names = new Array ( );
month_names[month_names.length] = "January";
month_names[month_names.length] = "February";
month_names[month_names.length] = "March";
month_names[month_names.length] = "April";
month_names[month_names.length] = "May";
month_names[month_names.length] = "June";
month_names[month_names.length] = "July";
month_names[month_names.length] = "August";
month_names[month_names.length] = "September";
month_names[month_names.length] = "October";
month_names[month_names.length] = "November";
month_names[month_names.length] = "December";

function getNextCalendarMonth(in_date)
{
if (in_date.getMonth() == 11) {
var out_date = new Date(in_date.getFullYear() + 1, 0, 1);
} else {
var out_date= new Date(in_date.getFullYear(), in_date.getMonth() + 1, 1);
}
return out_date;
}
function formatDate(in_date)
{
var out_string = "";
out_string = (in_date.getMonth()+1)+"/"+in_date.getDate()+"/"+in_date.getFullYear();
return out_string;
}

var mplus1=getNextCalendarMonth(new Date());
var mplus2=getNextCalendarMonth(mplus1);
var mplus3=getNextCalendarMonth(mplus2);
var mplus4=getNextCalendarMonth(mplus3);
document.write("<a href='http://www.localendar.com/public/n1lykme?start_date="+formatDate(mplus1)+"'>"+month_names[mplus1.getMonth()]+"</a><br/>");
document.write("<a href='http://www.localendar.com/public/n1lykme?start_date="+formatDate(mplus2)+"'>"+month_names[mplus2.getMonth()]+"</a><br/>");
document.write("<a href='http://www.localendar.com/public/n1lykme?start_date="+formatDate(mplus3)+"'>"+month_names[mplus3.getMonth()]+"</a><br/>");
document.write("<a href='http://www.localendar.com/public/n1lykme?start_date="+formatDate(mplus4)+"'>"+month_names[mplus4.getMonth()]+"</a><br/>");
</script>


This seemed FAQ-worthy: http://www.localendar.com/docs/display/lc/Dynamic+links+to+multiple+calendar+months
----------------------------------------
Marc Higgins
Support Associate, localendar.com
Follow us on Twitter! http://www.twitter.com/localendar_news

Posted by n1lykme at Feb 13, 2013, 5:01:45 PM
biggrin   Re: Show next month
Awesome! Great solution and customer support! Better than what I imagined.
Thank you so much!


Help! | Cobranding | Legal | Privacy Policy | About localendar.com | Contact Us