To Change theme of Default page

Topics: ASP.NET 2.0
Aug 19, 2011 at 9:33 AM

Can anybody help me in changing theme of default page? I will wait for the responce.

Aug 23, 2011 at 2:23 PM

I'm not sure I understand the question.  The theme for the site covers the home page as well as the other pages of the blog.  You can change themes via the admin area of the website.

If you find a theme that you want to use, but desire to change aspects of how the home page looks, then make a copy of that theme's folder, giving it a new name, switch to your new theme in the admin area, and then changes the style.css file of that new theme to suite your needs.

Does that help?  If not, just post back...

-Ron

Sep 9, 2011 at 4:30 AM
Edited Sep 9, 2011 at 4:35 AM

Hi All!

I think I have the same requirement. I have a semi-blog website and I am using the Standard theme.

I want the blog part to work normally -  to use the default style. But for the non-blog part, I want to use another style - one that hides the side panel.

So I have two styles - styles.css and stlyesNonBlog.css. But the site.master hard-codes the styles.css. How do I switch to stylesNonBlog on the fly depending the current page.

Thanks!

Coordinator
Sep 9, 2011 at 5:13 AM
galagerardo wrote:

So I have two styles - styles.css and stlyesNonBlog.css. But the site.master hard-codes the styles.css. How do I switch to stylesNonBlog on the fly depending the current page.

Here is example how to inject stylesheet to make style different for single post (in the site.master). Your conditions probably different, but same technique can be used.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BlogEngine.Core;

public partial class themes_Cogitation_site : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
		if (!IsPostBack)
        {
            // subscribe to post serving event
            Post.Serving += new EventHandler<ServingEventArgs>(Post_Serving);
        }
    }
	
    private void Post_Serving(object sender, ServingEventArgs e)
    {
        if (!IsPostBack && e.Location == ServingLocation.SinglePost)
        {
            // if serving single post - get a page handle
            System.Web.UI.Page pg = (System.Web.UI.Page)HttpContext.Current.CurrentHandler;
            bool added = false;

            // check if style sheet for single post 
            // already added to the page header
            foreach (Control ctl in pg.Header.Controls)
            {
                if (ctl.GetType() == typeof(HtmlLink))
                {  
                    HtmlLink lk = (HtmlLink)ctl;
                    if (lk.Attributes["href"] == "singlepost.css")
                    {
                        added = true;
                    }
                }
            }

            if (!added)
            {
                // if style sheet for single post not yet added
                // to the master page header - add it now
                HtmlLink link = new HtmlLink();
                link.Attributes.Add("href", "singlepost.css");
                link.Attributes.Add("media", "screen");
                link.Attributes.Add("rel", "stylesheet");
                link.Attributes.Add("type", "text/css");
                pg.Header.Controls.Add(link);
            }
        }  
    }
}

Sep 9, 2011 at 6:49 AM

Hi rtur!

Sorry, my bad. What I should have written is that I want one style for the pages and another style for the posts. Using the Standard theme, the pages will not display the side panel (Category List, Tag Cloud, etc.) but the posts will.

Thanks!

Coordinator
Sep 9, 2011 at 3:54 PM

Pretty much same code as above, only instead of ServingLocation.SinglePost check for ServingLocation.SinglePage. In that second css file, override styles you need for page to look different and you done. 

Sep 9, 2011 at 6:01 PM

Thanks for hanging in there for me rtur. I got it to work!