Forums

[resolved] How to make my post appear in a static page. (6 posts)

  1. generaljacksparrow
    Member
    Posted 1 year ago #

    Can someone tell me how to make the latest post appear in full in the static page.
    I need the home page to be a static one displaying the latest post in the bottom.
    Or can i have a static content in the top of the posts page and display the latest post in the bottom. Is that possible.
    Can anyone help me

  2. MichaelH
    Volunteer
    Posted 1 year ago #

    In your Page Template after the loop that displays that page content, add a loop to display that latest post...for example:

    <?php
    $args=array(
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
        the_content();
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  3. generaljacksparrow
    Member
    Posted 1 year ago #

    Hi micheal, thank you for your support.
    It really works, But i encounter a small problem,
    After that last post i need to put a link to 5 past posts.
    i used get posts plugin to display that before.
    I want that to display after this last post
    And another problem
    This post is not following the margins. Means it is aligned totally left.
    And this is the code of my page.php file.
    If you can help me, it would be very useful.

    <?php get_header(); ?>
    <div class="art-contentLayout">
    <div class="art-content">
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="art-Post">
        <div class="art-Post-body">
    <div class="art-Post-inner art-article">
    <h2 class="art-PostHeader">
    <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'kubrick'), the_title_attribute('echo=0')); ?>">
    <?php the_title(); ?>
    </a>
    </h2>
    <div class="art-PostContent">
    
              <?php if (is_search()) the_excerpt(); else the_content(__('Read the rest of this entry &raquo;', 'kubrick')); ?>
              <?php if (is_page() or is_single()) wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    
    </div>
    <div class="cleared"></div>
    
    </div>
    
    		<div class="cleared"></div>
        </div>
    </div>
    <?php
    $args=array(
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
        the_content();
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
    
    <?php comments_template(); ?>
    <?php endwhile; endif; ?>
    
    </div>
    
    </div>
    
    <div class="cleared"></div>
    
    <?php get_footer(); ?>
  4. generaljacksparrow
    Member
    Posted 1 year ago #

    Hi micheal, thank you for your support.
    It really works, But i encounter a small problem,
    After that last post i need to put a link to 5 past posts.
    i used get posts plugin to display that before.
    I want that to display after this last post
    And another problem
    This post is not following the margins. Means it is aligned totally left.
    And this is the code of my page.php file.
    If you can help me, it would be very useful.

    <?php get_header(); ?>
    <div class="art-contentLayout">
    <div class="art-content">
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="art-Post">
        <div class="art-Post-body">
    <div class="art-Post-inner art-article">
    <h2 class="art-PostHeader">
    <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'kubrick'), the_title_attribute('echo=0')); ?>">
    <?php the_title(); ?>
    </a>
    </h2>
    <div class="art-PostContent">
    
              <?php if (is_search()) the_excerpt(); else the_content(__('Read the rest of this entry &raquo;', 'kubrick')); ?>
              <?php if (is_page() or is_single()) wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    
    </div>
    <div class="cleared"></div>
    
    </div>
    
    		<div class="cleared"></div>
        </div>
    </div>
    <?php
    $args=array(
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
        the_content();
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
    
    <?php comments_template(); ?>
    <?php endwhile; endif; ?>
    
    </div>
    
    </div>
    
    <div class="cleared"></div>
    
    <?php get_footer(); ?>
  5. MichaelH
    Volunteer
    Posted 1 year ago #

    It would seem if you put your loop for 1 post and another loop for 5 posts (use 'offset'=>1,) those two loops should go right before the get_footer.

  6. generaljacksparrow
    Member
    Posted 1 year ago #

    Thank you, as i am new to this forum, i dont know how to use it. Now i got a hang of it.

Topic Closed

This topic has been closed to new replies.

About this Topic