Home Page News section
-
Ok, so I am fairly new to wordpress, but I know HTML and CSS quite well, still working on my php though ?? anyway, I have a static home page on my blog and was wondering if it is possible to add a “news” section to the homepage that will show all the post I make.
Thanks in Advance!
-
ok, that is over my head atm.. Are you able to explain it in more stupid terms lol?
ok, I’m starting to figure it out, but where would I place this code if I wanted this to happen on only 1 page, and not the whole site?
Take a look at conditional tags like
if( is_home() ) { //do stuff here }
so then to show the posts on the home page of the site in index.php my code should look like this?
if( is_front_page() ) { <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <!-- do stuff ... --> <?php endwhile; ?> <?php endif; ?>
Yes, but wrap the if statement in php tags
<?php if( is_front_page() ) { ?> // have_posts() loop code here <?php } ?>
ok, so here’s the body tag in my theme’s index.php
<body> <div id="wrapper"> <?php include(TEMPLATEPATH . "/menu.php"); ?> <?php include(TEMPLATEPATH . "/banner.php"); ?> <?php if($options['sidebarloc'] == 'left') { ?> <?php get_sidebar(); ?> <?php } ?> <div id="container"> <?php include(TEMPLATEPATH . "/postlist.php"); ?> </div> <?php if($options['sidebarloc'] == 'right') { ?> <?php get_sidebar(); ?> <?php } ?> <div class="clear"></div> <?php get_footer(); ?> </div> </body>
Would the loop code go right before the “clear” div?
so then the final loop code should look like this?
<?php if( is_front_page() ) { ?> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <!-- do stuff ... --> <?php endwhile; ?> <?php } ?>
Here is what I am putting in right before the div class “clear”
<?php if( is_front_page() ) { ?> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <li> <?php if (is_page() || is_single()) { ?> <h2 class="post-title"><?php the_title(); ?></h2> <?php } else { ?> <h2 class="post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <?php } ?> <?php if((!is_page() or $options['metaenabled']) or $options['txtsizechange']) { ?> <div class="post-meta"> <?php if(!is_page() or $options['metaenabled']) { ?> <div class="meta-left"> </div> <?php } ?> <div class="meta-right"> <?php if(!is_page() or $options['metaenabled']) { ?> <?php } ?> <?php if((is_single() or is_page()) and $options['txtsizechange']) { ?> <p class="changesize" onclick="changeFontSize()" title="Increase/Decrease font size"><span id="fontsmall">A</span> <span id="fontbig">A</span></p> <input type="hidden" value="inc" name="fontoperation" id="fontoperation" /> <?php } ?> </div> <?php endwhile; ?> <?php } ?>
And here is the error code I keep getting when I try to view it.
“Parse error: syntax error, unexpected T_ENDWHILE in /home1/victosb9/public_html/wp-content/themes/vbbc-2.0/index.php on line 45”
You’re missing <?php endif; ?> 2nd to last line
<?php endwhile; ?> <?php endif; ?> <?php } ?>
It looks like you’re also missing a closing </div> and tags at the end. Its important to close all tags in the loop, or else it can break your layout.
</li>
taghere is the code with the fixes
<?php if( is_front_page() ) { ?> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <li> <?php if (is_page() || is_single()) { ?> <h2 class="post-title"><?php the_title(); ?></h2> <?php } else { ?> <h2 class="post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <?php } ?> <?php if((!is_page() or $options['metaenabled']) or $options['txtsizechange']) { ?> <div class="post-meta"> <?php if(!is_page() or $options['metaenabled']) { ?> <div class="meta-left"> </div> <?php } ?> <div class="meta-right"> <?php if(!is_page() or $options['metaenabled']) { ?> <?php } ?> <?php if((is_single() or is_page()) and $options['txtsizechange']) { ?> <p class="changesize" onclick="changeFontSize()" title="Increase/Decrease font size"><span id="fontsmall">A</span> <span id="fontbig">A</span></p> <input type="hidden" value="inc" name="fontoperation" id="fontoperation" /> <?php } ?> </div> </div> </li> <?php endwhile; ?> <?php endif; ?> <?php } ?>
And the error it gives me now
“Parse error: syntax error, unexpected T_ENDWHILE in /home1/victosb9/public_html/wp-content/themes/vbbc-2.0/index.php on line 47”Looks like you’re missing another
<?php } ?>
for the line
<?php if((!is_page() or $options['metaenabled']) or $options['txtsizechange']) { ?>
ok, I got this code in
<?php if( is_front_page() ) { ?> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <li> <?php if (is_page() || is_single()) { ?> <h2 class="post-title"><?php the_title(); ?></h2> <?php } else { ?> <h2 class="post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <?php } ?> <?php if((!is_page() or $options['metaenabled']) or $options['txtsizechange']) { ?> <div class="post-meta"> <?php if(!is_page() or $options['metaenabled']) { ?> <div class="meta-left"> </div> <?php } ?> <div class="meta-right"> <?php if(!is_page() or $options['metaenabled']) { ?> <?php } ?> <?php if((is_single() or is_page()) and $options['txtsizechange']) { ?> <?php } ?> <p class="changesize" onclick="changeFontSize()" title="Increase/Decrease font size"><span id="fontsmall">A</span> <span id="fontbig">A</span></p> <input type="hidden" value="inc" name="fontoperation" id="fontoperation" /> <?php } ?> </div> </div> </li> <?php endwhile; ?> <?php endif; ?> <?php } ?>
and the page loads fine, but It is not showing the posts..
- The topic ‘Home Page News section’ is closed to new replies.