• Resolved aaronng91

    (@aaronng91)


    Hi,

    I was wondering if it is possible to have different layouts for the homepage vs single post/page. I’m planning to have a right sidebar on my homepage, but no sidebars (full-width) for the single posts/pages.

    Any advice on how to add a custom function to achieve this is much appreciated!

    Cheers,
    Aaron

Viewing 11 replies - 1 through 11 (of 11 total)
  • How are your code skills? Which theme are you using?

    If you know which template you’re using for the home page (usually home.php) or your posts page(s) (usually single.php) you can edit the code of those pages to omit or add sidebars.

    Depending on your theme, adding or removing sidebars may be built into it’s functionality.

    Thread Starter aaronng91

    (@aaronng91)

    Apologies for not being clear, I’m using Cazuela (https://www.ads-software.com/themes/cazuela).

    While I’m not experienced in PHP, I have some background in programming. Picking up the actual syntax wouldn’t be much of an issue. I’m just quite confused which function to call and what exactly I should change. If I’m not wrong, this theme allows you to change your layout, but it applies across the entire site.

    Thanks!

    I’m going to give you a super-quick run-down of what you’d need to change, as that’s all I have time for at the moment.

    If you want to remove the sidebar from the single post page, edit ‘single.php’ and remove this line:

    <?php get_sidebar(); ?>

    Then you’ll need to adjust the width of the content area by editing the class and id’s for the content area and applying rules to make it 100% width:

    <div id=”content” class=”site-content” role=”main”>

    Same goes for the page.php file.

    I know this is bare-bones info, but it should get you headed in the right direction..

    In Appearance > Customize select the full-width page layout (it will be your default). Now go to your home page and select the layout with the right sidebar.

    Does this solve your issue?

    In Appearance > Customize select the full-width page layout (it will be your default). Now go to your home page and select the layout with the right sidebar.

    Does this solve your issue?

    Thread Starter aaronng91

    (@aaronng91)

    @kcrusher – That seems to work out, now I just have to tidy up with some CSS changes. Thanks a lot!

    @dragan – I’ve tried the first part, but how do I “go to the home page and select the layout with the right sidebar”? I can’t seem to find such an option for the latter…

    If what Dragan is saying is correct, I may have been making this way more complicated than it needed to be.

    Go to Pages>All pages from the left hand navigation tab, click on Edit under your Home page and, in the right column there should be a template selector – it should have an option for one with a right sidebar.

    I’m guessing where these are based on how most themes work…and had assumed you had gone through all the built in customization options before asking how to modify the theme.

    Your Front page displays

    a) Your latest posts
    or
    b) A static page

    If it displays your latest posts you’ll have to go with what kcrusher wrote. If it’s set to display a static page, then you can go to that page and edit the Page Options > Post/Page layout settings.

    (thanks for helping out @kcrusher)

    Thread Starter aaronng91

    (@aaronng91)

    @kcrusher @dragan I figured out what you guys meant. Sorry about the confusion, as I wasn’t aware that the theme support manual overwriting of post template type.

    I would like my home page to have my latest posts instead of a static page. I assume the only way out to tis is to set the template of each post to full-width individually? Or is there a way to batch-edit the template type of all the posts (I assume it involves updating a certain column in the database)?

    Theme Author Slobodan Manic

    (@slobodanmanic)

    It is possible to achieve this, but I’m afraid that in order to really understand what’s going on you need to be familiar with how WordPress hooks work. I’ve written a quick function that should override default layout for homepage only, you should add it to functions.php file:

    function change_homepage_layout_class( $classes ) {
    	if( is_home() ) :
    		$classes['default_layout'] = 'layout-cp';
    	endif;
    
    	return $classes;
    }
    add_filter( 'thsp_current_layout', 'change_homepage_layout_class', 10 );

    Not tested, so please let me know if it works.

    Thread Starter aaronng91

    (@aaronng91)

    @Slobadan

    I’ve added the function to the theme and it works perfectly. Thank you very much. Love your theme!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Different layouts for homepage & single post/page’ is closed to new replies.