I need some help, I need to show multiple (about, events & contact) static pages in one static page (home). The most that I have read are post related what I need is the pages itself. Also where do I make the changes in the index.php or page.php? Any help would be appreciated.
You should create a Child theme to make your changes. If you do not, all of your changes will be lost if you update your theme.
You will not make changes in index.php or page.php. Instead, you will create a new template which contains 3 Loops. Each Loop will retrieve one of the 3 other pages that you want to display.
The exact way to do this will depend on your theme. In general, you can start with a copy of page.php renamed to something like frontpage.php, and modify it to be your template by adding the following code at the top:
<?php /* Template Name: Front Page */ ?>
Then add the code for the 3 loops to replace the original loop.
Ok, I created a child theme and inside are two files style.css & frontpage.php. I place the loops for the pages I wanted to show (about & events). But its still not working. 🙁
Can you please help me?
This is whats inside my frontpage.php
<?php /* Template Name: Front Page */ ?> get_header(); ?> <div id="primary"> <div id="content" class="narrowcolumn"> <?php $about = get_posts('page_id=12'); foreach($about as $post) : setup_postdata($post); ?> <h2><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></h2> <?php the_content(); ?> <?php endforeach; ?> <?php $events = get_posts('page_id=25'); foreach($events as $post) : setup_postdata($post); ?> <h2><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></h2> <?php the_content(); ?> <?php endforeach; ?> </div><!-- #primary --> <?php get_footer(); ?>
Did you create a new blank page for your front page and assign ‘Front Page’ as the template?
If so, and it didn’t work, please post a link to your site where the page can be seen.
Hmm no, I didn’t create one. Sorry this might sound stupid but how do I do that? Do I create it as part of the .php files or just Page > Add New Page ? And how can I choose a template for this?
Also here’s my site: http://kiwirootsmusic.com/
Use Pages->Add New. Put in a title, leave the content empty. Under ‘Page Attributes’ in the right column, find the dropdown under ‘Template’ and select ‘Front Page’. Click ‘Publish’.
Next, go to Admin->Settings->Reading and click ‘A static page’. Choose your new Page in the dropdown and click ‘Save Changes’.
I can’t find the Front Page template in the Template dropdown. How do I make it show up? Question though, when I created the frontpage.php file I placed it under the Child Theme is that correct?
Sorry I have so many questions. Thanks for being patient.
frontpage.php does go in the Child theme folder. Did you activate the child theme?
Ok, I hope I’m getting close I activated the child theme and was able to select frontpage template. But now the problem is there’s nothing to show so my site looks like this http://kiwirootsmusic.com
On second thought I think I’m not getting close 🙁
OK – you have a small error in the template. Change this:
<?php get_header(); ?>
You should look at this tutorial:
Ok I now have the blank front page in my home page. But I guess I still have a problem in showing the 2 static pages I have in the front page. Is there something wrong with the loop I have that’s it’s not showing anything?
Two problems (assuming the code you first posted is still what you are using):
First, you need to add the post_type argument to get_posts like this:
$about = get_posts('page_id=1114&post_type=page');
Second, you are missing a closing div for #content. It needs to go just above the closing div for #primary:
</div><!-- #content --> </div><!-- #primary -->
Wow!!! it’s working!!! Thank you so much vtxyzzy.
Now I just have to figure out how to align it 🙂
Another question, how can I include the sidebar without placing the loop below it?
<?php get_sidebar('right'); ?>
This is what I have right now… http://www.kiwirootsmusic.com
<?php /* Template Name: Front Page */ ?> <?php get_header(); ?> <?php get_sidebar('right'); ?> <div id="primary"> <div id="content" class="narrowcolumn"> <?php $about = get_posts('page_id=12&post_type=page'); foreach($about as $post) : setup_postdata($post); ?>
- The topic ‘multiple static page in one static page’ is closed to new replies.