Front Page Posts
-
My website is amanofreason.com. Right now, my front page (home) displays all my posts from varied categories. However, I would only like posts under the category name Today’s Headlines to appear on my homepage. How can I accomplish this? All input is much appreciated.
-
Where you see the template name Latest News this could be what ever you want the template to be called, there are some extra comments I have placed in here in case you want thumb nails.
* note this should be placed in your child theme folder under “your site”/wp-content/themes/”your child theme”/page-templates, you can then create the page and select the new template.
This is based on the Twenty Twelve Theme.<?php /** * Template Name: Latest News * * This is the template that displays all pages by default. * Please note that this is the WordPress construct of pages * and that other 'pages' on your WordPress site will use a * different template. * * @package WordPress * @subpackage Twenty_Twelve * @since Twenty Twelve 1.0 */ get_header(); ?> <div id="primary"> <div id="content" role="main"> <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content', 'page' ); ?> <!--Klick Design Added to show latest post on Latest News Page--> <div> <?php $args = array( 'numberposts' => 3 ); $lastposts = get_posts( $args ); foreach($lastposts as $post) : setup_postdata($post); ?> <h2>Latest News Article <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <?php the_post_thumbnail(); the_excerpt(); ?><!--If you want to include images and full post use the_content and for thumbnails the_post_thumbnail(); see http://codex.ww.wp.xz.cn/Function_Reference/the_post_thumbnail --> <?php endforeach; ?></div><!--#entry-content--> <!--end of post addition by Klick Design http://www.klick-design.co.uk/wordpress-latest-news-page-with-excerpts/--> <?php endwhile; // end of the loop. ?> </div><!-- #content --> </div><!-- #primary --> <?php get_sidebar(); ?> <?php get_footer(); ?>you need to overwrite the WordPress default query. WordPress automatically query for you normally apart from custom template.
please check here
http://codex.ww.wp.xz.cn/Function_Reference/query_postsUsage is
// if you want to use the id, you can get the id by hovering the category name and it show at bottom left corner of the window. query_posts( 'cat=1' ); //if you want to use slug which you can find by click edit link of the category name in category section query_posts( 'cat=headline' ); //just before this while loop while ( have_posts() ) : the_post(); echo '<li>'; the_title(); echo '</li>'; endwhile; // Reset Query wp_reset_query();Hope you would be okay with this 🙂
Cheers KaugKo Can you see any issues with this?
<?php /** * Template Name: Latest News * * This is the template that displays all pages by default. * Please note that this is the WordPress construct of pages * and that other 'pages' on your WordPress site will use a * different template. * * @package WordPress * @subpackage Twenty_Twelve * @since Twenty Twelve 1.0 */ get_header(); ?> <div id="primary" class="site-content"> <div id="content" role="main"> <?php $the_query = new WP_Query( $args ); while ( have_posts() ) : the_post(); //added Wp_Query?> <?php get_template_part( 'content', 'page' ); ?> <!--Klick Design Added to show latest post on Latest News Page--> <div class="entry-content"> <?php $args = array( 'numberposts' => 3 ); $lastposts = get_posts( $args ); foreach($lastposts as $post) : setup_postdata($post); ?> <h2>Latest News Article <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <?php the_post_thumbnail(); the_excerpt(); ?><!--If you want to include images and full post use the_content and for thumbnails the_post_thumbnail(); see http://codex.ww.wp.xz.cn/Function_Reference/the_post_thumbnail --> <?php endforeach; ?></div><!--#entry-content--> <!--end of post addition by Klick Design --> <?php endwhile; wp_reset_postdata();// end of the loop. and wp_reset?> </div><!-- #content --> </div><!-- #primary --> <?php get_sidebar(); ?> <?php get_footer(); ?>Added WP_Query for get_posts and WP_Reset.
and use ‘category’ => 1 to pick the category?Thank you for the responses. However, much of the code and query stuff is beyond me. Is there any way you could possibly simplify what I need to do (in terms for someone who does not know code.) Thanks again for your help.
Have you posted in your themes support might be worth ago.
The topic ‘Front Page Posts’ is closed to new replies.