WordPress.org

Forums

How can i put posts in a page except home page (5 posts)

  1. shilpa123
    Member
    Posted 6 years ago #

    Hi

    May you please tell me how can we displays different posts in a particular page execept home page suppose i am making a page - Test - by write page and after that i wrote 5 posts and i want that all these posts will be display on the test page how can i set up this setting please guide me. I am able to extend the page by page parent field. but in a page i want to configure post in it. Please reply to me ASAP.

    Thanks in Advance
    Shilpa

  2. webfwrd
    Member
    Posted 6 years ago #

    Put this code in whatever place (inside the theme) you want the posts to display -

    <?php
    global $post;
    if (is_page()) {
    	// Put you code for displaying post
    } else {
    	// Put what to display if it's not page
    }
    ?>
  3. shilpa123
    Member
    Posted 6 years ago #

    hi

    please tell me in the details i am using theme atahualpa.2.01.zip_FILES/ theme please tell me in the details where in which folder and in which file we can place that code. I am not getting it completly.

    Thanks and Regards
    Shilpa

  4. shilpa123
    Member
    Posted 6 years ago #

    hi

    i am just downloading the theme and adding posts and page by wp-admin.

  5. ryancp
    Member
    Posted 6 years ago #

    The way I handle this is to create a new page template in your theme's root directory. Call it "page-template-whatever.php".
    In that new file, you can add this code:

    <?php
    /*
    Template Name: YourTemplateName
    */
    ?>
    
    <?php get_header(); ?>
    
    	<div id="content">
    
    	<h1><?php the_title(); ?></h1>
    
    	<?php query_posts("cat=27&showposts=5"); ?>
    			<?php if (have_posts()) : ?>
    				<?php while (have_posts()) : the_post(); ?>
    
    				<div class="post" style="margin-bottom: 15px;">
    					<?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> -->
    
    					<p style="margin-top: -10px; margin-bottom: -8px;"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><strong><?php the_title(); ?></strong></a>
    
    					<?php the_excerpt('Read the rest of this entry &raquo;'); ?>
    				</div>
    
    				<?php endwhile; ?>
    
    			<?php else : ?>
    
    				<h2 class="center">Not Found</h2>
    				<p class="center">Sorry, but you are looking for something that isn't here.
    
    				<?php include (TEMPLATEPATH . "/searchform.php"); ?>
    
    			<?php endif; ?>
    
    	</div> <!-- end #content -->
    
    <?php get_footer(); ?>

    The top part just tells WordPress what the template name will be, and when you write/edit your page, you can select this as a template and it will process this code.

    Basically, this is a static page that gets the most recent 5 posts that are in the category with ID of 27. This is just an example. Feel free to look in the codex (http://codex.wordpress.org/Pages) on how to modify this to suit your needs.

    http://ryanpharis.com

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags