[resolved] Latest post on static page (6 posts)

  1. Red1
    Posted 7 years ago #

    I'd like to be able to position the latest (single) post of my "news" category on a static page we use as a home/index page.

    Is there a solution available?

  2. MichaelH
    Posted 7 years ago #

    Add this to a page template to display one post from category 17:

    $args = array(
      'numberposts' => 1,
      'cat' => 17
    if ($posts) {
    foreach($posts as $post) {
    <p><?php the_time('m.d.y') ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    <?php the_content(); ?>
    <?php }
  3. Red1
    Posted 7 years ago #

    Thanks for that Michael.
    I have managed to get the post in the page. My problem is position and format. I would prefer it positioned under the first block of introductory text and formatted as per the standard css for a post.
    If you have time to look and advise http://www.rotherhamadvancedmotorcyclysts.com
    I would be most grateful.
    Many thanks

  4. Red1
    Posted 7 years ago #

    I have another issue with the response.
    The posts are now appearing on all "pages".
    I've saved the original page.php as page1.php in the hope of using it as a template and then remove the new code from the original page.php, but as a novice I'm unsure how to go about it.


  5. MichaelH
    Posted 7 years ago #

    You need to assign page1.php as the Template on the Page. So edit that Page in your admin and point to page1.php as the template. If page1.php does not show as a choice then read this: Why is there no Page Template option when writing or editing a Page?

  6. spiritbased
    Posted 6 years ago #

    Michael, your code above is different from the normal loop for a 'single.php' page. How would I code so that the post shown on the page is the same as a regular post?

    EDIT Got it working, but previous_post_link and next_post_link don't appear, I guess because they aren't in The Loop?

Topic Closed

This topic has been closed to new replies.

About this Topic