Pages

Tuesday, February 5, 2013

How to display total blog posts in a static page?

To display total blog posts in a static page which are created by the developer, need to follow below steps..

1. Create a page with the name posts.php in theme folder which the site using.
2. Copy paste below code

<?php
/**
 * Template Name: Posts Page
 * Description: A Page Template that adds a sidebar to pages
 *
 * @package WordPress
 * @subpackage Twenty_Eleven

 * @since Twenty Eleven 1.0
 */

get_header(); ?>

            <div id="primary" style="width:700px !important;">
            <h1 class="entry-title" style="padding-left:25px;">Blog Posts</h1>
            <div id="content" role="main">



<div id="" style="width:675px;text-align:justify; margin-left: -25px;padding-top:5px;">
<div id="my-static-front-posts">
<?php
$custom_loop = new WP_Query('showposts=5&orderby=date');
if ( $custom_loop->have_posts() ) :
while ( $custom_loop->have_posts() ) : $custom_loop->the_post();
echo '<div class="post type-post hentry post_box top" style="padding-top:5px;">';
echo '<div class="headline_area"><h2 class="entry-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>';
echo '<div class="entry-meta">Posted on ' . get_the_date() . '</div></div>';
echo '<div class="format_text entry-content" style="width:100%;">' . get_the_excerpt() . '</div>';
echo '</div>';
endwhile;
wp_reset_query();
endif;
?></div>
            </div>
            </div><!-- #content -->
        </div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
 3. Add a new page from admin side and select Template in Page Attribute as Posts Page(This is the template name which is in posts.php file).
4. Finish....

No comments:

Post a Comment