the blogmonths doesn't show culture specific month and year values. it should use calendar methods to get month and year. (this doesn't work for persian culture when using jalali calendar.)
unfortunately I've not yet learned asp.net MVC and entity framework. I'm changing NopCommerceStore\Modules\BlogMonths.ascx.cs of nop 1.9 and after it's complete I'll post the new file, describing the changes. regards.
Ok these are the changes I see are needed, by now.
I tried to comment the original code, and put the new code instead of it. I wish I haven't forgotten any in blogmonth BindData() and RenderMonths() need change:
private void BindData() { var blogPosts = this.BlogService.GetAllBlogPosts(NopContext.Current.WorkingLanguage.LanguageId); if (blogPosts.Count > 0) { var months = new SortedDictionary<DateTime, int>();
DateTime first = blogPosts[blogPosts.Count-1].CreatedOn;
while (DateTime.SpecifyKind(first, DateTimeKind.Utc) <= DateTime.UtcNow.AddMonths(1)) { var list = blogPosts.GetPostsByDate(new DateTime(first.Year, first.Month, 1), new DateTime(first.Year, first.Month, 1).AddMonths(1).AddSeconds(-1)); if (list.Count > 0) { System.Globalization.Calendar currentCalendar = Thread.CurrentThread.CurrentCulture.Calendar; //DateTime date = new DateTime(first.Year, first.Month, 1); DateTime date = new DateTime(currentCalendar.GetYear(first),currentCalendar.GetMonth(first), 1,currentCalendar);
HtmlGenericControl ul = new HtmlGenericControl("ul"); ul.Attributes.Add("id", "blogMonthList"); HtmlGenericControl year = null; HtmlGenericControl list = null; int current = 0;
foreach (DateTime date in Months.Keys) { if (current == 0) current = currentCalendar.GetYear(date); //current = date.Year;
//if (date.Year > current || ul.Controls.Count == 0) if (currentCalendar.GetYear(date) > current || ul.Controls.Count == 0) { list = new HtmlGenericControl("ul"); //list.ID = "year" + date.Year.ToString(); list.ID = "year" + currentCalendar.GetYear(date);
year = new HtmlGenericControl("li"); year.Attributes.Add("class", "year"); //year.InnerHtml = date.Year.ToString(); year.InnerHtml = currentCalendar.GetYear(date).ToString(); year.Controls.Add(list);
ul.Controls.AddAt(0, year); }
HtmlGenericControl li = new HtmlGenericControl("li");
--------and in blog.ascx.cs where lTitle.Text is set, code needs to change like this int filterYear = System.Threading.Thread.CurrentThread.CurrentCulture.Calendar.GetYear(this.FilterByMonth.Value); lTitle.Text = string.Format(GetLocaleResourceString("Blog.FilteredByMonth"), filterYear, this.FilterByMonth.Value.ToString("MMMM")); //lTitle.Text = string.Format(GetLocaleResourceString("Blog.FilteredByMonth"), this.FilterByMonth.Value.Year, this.FilterByMonth.Value.ToString("MMMM"));
---------- and also code for FilterByMonth
public DateTime? FilterByMonth { get { DateTime? result = null; string dateStr = CommonHelper.QueryString("month"); if (!String.IsNullOrEmpty(dateStr)) { string[] tempDate = dateStr.Split(new char[] { '-' }); if (tempDate.Length == 2) { //result = new DateTime(Convert.ToInt32(tempDate[0]), Convert.ToInt32(tempDate[1]), 1); result = new DateTime(Convert.ToInt32(tempDate[0]), Convert.ToInt32(tempDate[1]), 1, System.Threading.Thread.CurrentThread.CurrentCulture.Calendar); } } return result; } }
It is important to edit date/time of news or blogposts. At this there is no option for manually settings date/time of post in blog (and news too). Maybe you can implement this in new edition :-)
Hello The date is displayed incorrectly in the archive section of the blog. I am using version 4.50 and the glorious Iranian calendar. Please tell me which code I can edit to display the date correctly. Thank You!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.