StudioPress Community Forums
  StudioPress Community Forums > Forums > General Discussion
For help and support, access to your downloads, or to manage your account please log into My StudioPress.

These forums have been set to read-only so you can browse the existing topics for any questions you may have.

For general discussion on WordPress, CSS and design (NOT for support) visit the new Community Forums.
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-24-2010, 11:58 AM
tutorials's Avatar
tutorials tutorials is offline
Training
 
Join Date: Aug 2009
Location: cyberspace
Posts: 825
Default How to Add Additional Sections to the Homepage

One of the most popular requests is how to create additional sections for the homepage. Currently the code that's built into the home.php file is tied to the Theme Options page, so the easiest way to customize this is by resorting back to the original way we had coded these types of sections.

Creating an additional block within .homepageleft (first section below the FCG) on the homepage

Step #1
Open up your home.php file, and copy this code:

Code:
<div class="hpfeatured">

            <h3><?php echo  cat_id_to_name(get_theme_mod('featured_top_left')); ?></h3>

                

                <?php $recent = new  WP_Query("cat=".get_theme_mod('featured_top_left')."&showposts=".get_theme_mod('featured_top_left_num'));  while($recent->have_posts()) : $recent->the_post();?>

                <?php if( get_post_meta($post->ID, "thumb", true)  ): ?>

                <a href="<?php the_permalink() ?>"  rel="bookmark"><img class="thumb" src="<?php  bloginfo('template_directory'); ?>/tools/timthumb.php?src=<?php  echo get_post_meta($post->ID, "thumb", $single = true);  ?>&amp;h=<?php echo  get_theme_mod('featured_top_left_thumb_height');  ?>&amp;w=<?php echo  get_theme_mod('featured_top_left_thumb_width'); ?>&amp;zc=1"  alt="<?php the_title(); ?>" /></a>    

                <?php else: ?>

                <?php endif; ?>                    

                

                <strong><a href="<?php the_permalink()  ?>" rel="bookmark"><?php the_title();  ?></a></strong>

                <?php the_content_limit(80, ""); ?>

                

                <hr/>

                

                <?php endwhile; ?>

                

                <?php if(get_theme_mod('featured_top_left')) : ?>

                <strong><a href="<?php echo  get_category_link(get_theme_mod('featured_top_left')); ?>"  rel="bookmark"><?php _e("Read more posts from ", 'studiopress');  echo get_cat_name(get_theme_mod('featured_top_left'));  ?></a></strong>

                <?php endif; ?>

                

            </div>
Step #2
Paste it just below where you found it - in other words, you'll have this code now twice in your home.php file, one on top of the other. In order to easily work with the code, take this code:

Code:
<?php $recent = new  WP_Query("cat=".get_theme_mod('featured_top_left')."&showposts=".get_theme_mod('featured_top_left_num'));  while($recent->have_posts()) :  $recent->the_post();?>
And replace it with this code:

Code:
<?php $recent = new WP_Query("cat=1&showposts=1");  while($recent->have_posts()) :  $recent->the_post();?>
What you have just done is replace what we built which tied into the theme options page to something easier to work with, and easier to replicate. Change the cat=1 to whatever category ID you want to display, and obviously change showposts=1 to however many posts that you want to display.

Step #3
You will also need to change the Headline code, so take this code:

Code:
<h3><?php echo  cat_id_to_name(get_theme_mod('featured_top_left'));  ?></h3>
And replace it with the headline of your choice, similar to this:

Code:
<h3>Featured Category</h3>
Step #4
Locate this code:
Code:
<strong><a href="<?php echo get_category_link(get_theme_mod('featured_top_left')); ?>" rel="bookmark"><?php _e("Read More Posts From This Category"); ?></a></strong>
And replace it with this code, adding the URL to the category's archive page and the title of the category:
Code:
<strong><a href="URL GOES HERE">More Posts From  CATEGORY NAME GOES HERE</a></strong>
Creating an additional block within .homepageright
This entails the same steps as outlined for .homepageleft except wherever .homepageleft uses featured_top_left .homepageright uses featured_top_right

Creating an additional block within .homepagebottom on the homepage

Step #1
Open up your home.php file, and copy this code:

Code:
<div class="hpbottom">

            <h3><?php echo  cat_id_to_name(get_theme_mod('featured_bottom')); ?></h3>

                

                <?php $recent = new  WP_Query("cat=".get_theme_mod('featured_bottom')."&showposts=".get_theme_mod('featured_bottom_num'));  while($recent->have_posts()) : $recent->the_post();?>

                <?php if( get_post_meta($post->ID, "thumb", true)  ): ?>

                <a href="<?php the_permalink() ?>"  rel="bookmark"><img class="thumb" src="<?php  bloginfo('template_directory'); ?>/tools/timthumb.php?src=<?php  echo get_post_meta($post->ID, "thumb", $single = true);  ?>&amp;h=<?php echo  get_theme_mod('featured_bottom_thumb_height'); ?>&amp;w=<?php  echo get_theme_mod('featured_bottom_thumb_width'); ?>&amp;zc=1"  alt="<?php the_title(); ?>" /></a>    

                <?php else: ?>

                <?php endif; ?>                

                

                <strong><a href="<?php the_permalink()  ?>" rel="bookmark"><?php the_title();  ?></a></strong>

                <?php the_content_limit(350, __("[Read more of this  review]", 'studiopress')); ?>

                    

                <hr/>

                    

                <?php endwhile; ?>

                        

                <?php if(get_theme_mod('featured_bottom')) : ?>

                <strong><a href="<?php echo  get_category_link(get_theme_mod('featured_bottom')); ?>"  rel="bookmark"><?php _e("Read more posts from ", 'studiopress');  echo get_cat_name(get_theme_mod('featured_bottom'));  ?></a></strong>

                <?php endif; ?>

            

            </div>
Step #2
Paste it just below where you found it - in other words, you'll have this code now twice in your home.php file, one on top of the other. In order to easily work with the code, take this code:

Code:
<?php $recent = new  WP_Query("cat=".get_theme_mod('featured_bottom')."&showposts=".get_theme_mod('featured_bottom_num'));  while($recent->have_posts()) :  $recent->the_post();?>
And replace it with this code:

Code:
<?php $recent = new WP_Query("cat=1&showposts=1");  while($recent->have_posts()) :  $recent->the_post();?>
What you have just done is replace what we built which tied into the theme options page to something easier to work with, and easier to replicate. Change the cat=1 to whatever category ID you want to display, and obviously change showposts=1 to however many posts that you want to display.

Step #3
You will also need to change the Headline code, so take this code:

Code:
<h3><?php echo  cat_id_to_name(get_theme_mod('featured_bottom'));  ?></h3>
And replace it with the headline of your choice, similar to this:

Code:
<h3>Featured Category</h3>
Step #4
Locate this code:
Code:
<?php if(get_theme_mod('featured_bottom')) : ?>

                <strong><a href="<?php echo  get_category_link(get_theme_mod('featured_bottom')); ?>"  rel="bookmark"><?php _e("Read more posts from ", 'studiopress');  echo get_cat_name(get_theme_mod('featured_bottom'));  ?></a></strong>
And replace it with this code, adding the URL to the category's archive page and the title of the category:
Code:
<strong><a href="URL GOES HERE">More Posts From  CATEGORY NAME GOES HERE</a></strong>
Finally you will need to edit the style sheet to create space between the new elements

Open style.css and look for these selectors:

Code:
.hpbottom {

    float: left;

    width: 590px;

    margin: 0px;

    padding: 10px;

    display: inline;

    }
Code:
.hpfeatured {

    background: #FFFFFF url(images/featuredtop.gif) top no-repeat;

    float: left;

    width: 280px;

    margin: 0px;

    padding: 10px 10px 10px 10px;

    border: 1px solid #DDDDDD;

    }
and change them to this:

Code:
.hpbottom {

    float: left;

    width: 590px;

    margin: 0px 0px 10px;

    padding: 10px;

    display: inline;

    }
Code:
.hpfeatured {

    background: #FFFFFF url(images/featuredtop.gif) top no-repeat;

    float: left;

    width: 280px;

    margin: 0px 0px 10px;

    padding: 10px 10px 10px 10px;

    border: 1px solid #DDDDDD;

    }

Last edited by SoZo; 06-24-2010 at 11:05 AM.
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Add Additional Sections to Your Homepage MVF45 General Discussion 13 07-08-2010 05:09 PM
How to Add Additional Sections to the Homepage tutorials General Discussion 1 03-01-2010 08:25 AM
How do I add additional Category sections to the homepage Eski99 General Discussion 4 11-27-2009 08:27 AM
How to Add Additional Sections to Your Homepage tutorials General Discussion 1 11-02-2009 10:31 AM
How to Add Additional Sections to Your Homepage tutorials General Discussion 1 10-14-2009 01:03 PM


All times are GMT -5. The time now is 07:31 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.