WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] What's the best way to setup a home page with different content sections? (12 posts)

  1. matius
    Member
    Posted 4 years ago #

    This is sort of a general question because I'm not sure if this is a common task, but I'm using WP as a CMS & need my home page to have a different layout than the inside pages. Yet, I need everything to be editable under this WP install.

    Everything so far is cool, but I need certain content coming into the home page that won't be on the inside pages.

    Does this require setting up new fields in the database & creating new functions/pages, etc. to add a new content section to the template?

    Or is there a better way to create different sections for one page and not another?

    Sorry if that's a jumbled mess but hopefully somebody will know what I'm trying to say ;)

  2. Michael Fields
    Themer
    Posted 4 years ago #

    I think that widgets might be your best bet. There is a great tutorial here. on creating them.

    In your scenario, I would create multiple html lists in Page Template. You would then need to register these lists as widgets in your functions.php file. FYI - Widgets do not have to be limited to a "sidebar" as a sidebar is basically an unordered list as far as WordPress Core sees understands it.

    Hopefully this will lead you in the right direction!
    -Mike

  3. matius
    Member
    Posted 4 years ago #

    Mike, thanks for the tip! I will check into it.

  4. matius
    Member
    Posted 4 years ago #

    Mike, are you saying that I would need to register the widgets separately because the sidebar is already registered?

    Reason I'm asking is because I just went through a widget tutorial & didn't need to register them in functions.php at all... function.php confuses me ;)

    I'll take a look through your links again to see if I can find what's missing.

    Thanks again.

  5. Michael Fields
    Themer
    Posted 4 years ago #

    Mike, are you saying that I would need to register the widgets separately because the sidebar is already registered?

    Opps, I wrote this out incorrectly, you will need to register the lists as "Sidebars" - not "Widgets"... sometimes all this WordPress jargon can get confusing :)

    Here's a working Page Template that should allow you to create dynamically editable areas on your home page. You will need to copy this code, paste it into a new file and save as t-homepage.php. Upload this file to your site's current theme directory.

    You can then create a new page in the WordPress Administration Panels and set it's Page Template to "Frontpage".

    The template below will generate a WordPress loop width 2 widgetized regions below it.

    Hope this Helps,
    Mike

    <?php
    /*
    Template Name: Frontpage
    Author: Michael Fields
    License: GPL 2
    */
    
    /* Register widgetized area with WordPress */
    register_sidebar( array(
    	'name' => __( 'Homepage 1', $platypus->locale ),
    	'id' => __( 'homepage_1' )
    	) );
    register_sidebar( array(
    	'name' => __( 'Homepage 2', $platypus->locale ),
    	'id' => __( 'homepage_2' )
    	) );
    
    /* Helper function which prints a single widgetized area. */
    function mf_custom_sidebar( $id ) {
    	print "\n\n" . '<div id="' . $id . '">';
    	print "\n\t" . '<ul>';
    	dynamic_sidebar( $id );
    	print "\n\t" . '</ul>';
    	print "\n\t" . '</div>';
    }
    
    get_header();
    
    print '<div id="content">';
    
    /* WordPress Loop Condensed. */
    if ( have_posts() ) {
    	while ( have_posts() ) {
    		the_post();
    		the_title( '<h1>', '</h1>' );
    		the_content();
    		comments_template();
    	}
    	print '<div class="clear"></div>';
    }
    
    /* Create as many Widgetized Areas Here. */
    mf_custom_sidebar( 'homepage_1' );
    mf_custom_sidebar( 'homepage_2' );
    
    print '</div>';
    
    get_sidebar();
    get_footer();
    
    ?>
  6. vtxyzzy
    Member
    Posted 4 years ago #

    Matius, I don't know if mfields solved your problem or not. I am not quite clear on what you want. If you just want a static front page with posts from several different categories on it, you can do that with multiple loops in a template.

    Take a look at BluegrassMiataClub.com. It has a static front page with a 'Welcome' section at the top. Then there are three category sections below: 'Message From Our Club', 'Monthly Meetings', and 'Down The Road'. Each category section shows the most recent post in its category, but it could easily show more than one.

    If this seems like what you want to do, use the About->Contact Us form to email me - Mac McDonald, and I will be glad to try to answer questions about the site.

  7. matius
    Member
    Posted 4 years ago #

    Thanks vtxyzzy, all I'm trying to do is organize my home page differently than the inside pages (using WP as a CMS).

    So basically, I need to create new editable content sections for the home page, that won't appear on the inside pages.

    So if an inside page has an article and a sub nav, the home page will a more narrow welcome text and 4 different other sections.

    Mike, thanks for the code. I think I see what's going on there...

  8. matius
    Member
    Posted 4 years ago #

    I guess my question would be (and forgive if it's plain obvious) how I populate the widgets... by creating a new file for each I create?

  9. matius
    Member
    Posted 4 years ago #

    Oh, I see you have to add the registers to functions.php to get this working.

    Can these be removed from t-homepage.php?

  10. Michael Fields
    Themer
    Posted 4 years ago #

    Oh, I see you have to add the registers to functions.php to get this working.

    Can these be removed from t-homepage.php?

    Yep. If you add them to functions.php you should be able to add widgets in you admin. Sorry for the oversight on my part.

  11. matius
    Member
    Posted 4 years ago #

    No worries man, this has saved my day. Thanks so much - awesome code!

  12. Michael Fields
    Themer
    Posted 4 years ago #

    No problem, glad it worked out for you!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.