WordPress.org

Ready to get started?Download WordPress

Forums

want the most recent post only, on front page. (14 posts)

  1. gallo
    Member
    Posted 5 years ago #

    hello -

    i'd like my front page to have the most recent post from the blog only. i'd like for the viewer to be able to click on "earlier posts" and have them go to a page that has the 10 (or so) previous posts. i'm using wordpress as more of a website rather than a typical blog. so, i'm using the blog as a news section. i just want 1 post so that i can code some other information under the post on the main page (hopefully).

    if i set the "number of posts to show on blog pages" to 1 in the settings then all of the blog pages will just have 1, so that doesn't work.

    i tried using the "custom query string" plugin, however with no luck.

    i've also read much of this: http://codex.wordpress.org/Template_Tags/query_posts

    but, wasn't able to get anything to work appropriately from that source either.

    is there a somewhat straight forward simple way to execute this?

    thanks very much. : )

  2. Austin Matzko
    Member
    Posted 5 years ago #

    If there isn't already a home.php template file in your theme, create one by copying index.php as home.php. Then edit it and somewhere at the top put the following:

    query_posts(array('showposts' => 1));

  3. gallo
    Member
    Posted 5 years ago #

    thanks for the reply and the help filosofo.

    i did as you said and it didn't work. i believe i did it correctly. it actually ended up showing your code up at the top of the website. as in - you can see the actual code in the browser.

    i copied the index.php file, renamed it home.php, and added your code to the very top. i tried a few other places too.

    so, the home.php file looked like this:

    query_posts(array('showposts' => 1));
    
    <?php get_header(); ?>
    
    <div id="blog">
    
    <?php require_once (TEMPLATEPATH . '/navigation.php'); ?>
    
    	<div id="main">
    
    		<?php if (have_posts()) : ?>
    			<?php while (have_posts()) : the_post(); ?>
    
    				<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permalink to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    				<h3><?php the_time('F jS, Y') ?></h3>
    
    				<?php the_content('Continue reading this entry &raquo;'); ?>
    
    				<p class="meta">
    					<span class="tags"><?php the_category(', ') ?></span> |
    					<span class="comments"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span>
    					<?php
    					if ('open' == $post->ping_status) :
    					?>
    					<?php
    					endif; ?>
    					<?php edit_post_link(' Edit','|',''); ?>
    
    			<?php endwhile; ?>
    
    			<ul class="postnav">
    				<li class="left"><?php next_posts_link('&laquo; Earlier Posts') ?>&nbsp;</li>
    				<li class="right">&nbsp;<?php previous_posts_link('Later Posts &raquo;') ?></li>
    			</ul>
    
    		<?php else : ?>
    			<h2>Not Found</h2>
    			Sorry, but you are looking for something that just isn't here.
    
    			<?php include_once (TEMPLATEPATH . "/searchform.php"); ?>
    		<?php endif; ?>
    
    	</div>
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>

    any further thoughts?

    oh, i should also mention that in addition to seeing the code on the site, you could still see all of my posts on the front page as well.

    thanks a lot for your help and anyone else that might have some insight.

    p.s. - i left the index.php on the server as well. is that correct?

  4. Austin Matzko
    Member
    Posted 5 years ago #

    Change the first part to:

    <?php
    query_posts(array('showposts' => 1));
    get_header(); ?>
  5. gallo
    Member
    Posted 5 years ago #

    thank you again.

    that worked well, but only half way.

    the front page it now exactly how i want it with just the most recent post.

    however, when i click on "earlier posts" it brings me to another page with just the first post. an identical page. the URL is different, but the content is the same.

    it brings me to this extention: website.com/?paged=2

    that seems like the proper extension, but i'm not sure why it's still the front page content wise.

    any thoughts?

  6. gallo
    Member
    Posted 5 years ago #

    if it's okay i have another question/comment for anyone with some insight..

    after i get this to work i'm planning to have some more content under this "single recent post" on the front page. not just text, but some images as well. i'm not well versed in php at all so i'd want to use html and sadly i would use tables if possible.

    so, perhaps, i'm better off turning the front page into a static page. and then putting the the "blog" on another page. and then putting the "single recent post" on the static front page. logistically, does that make more sense given my desired end result?

    i'm realizing it may not be ideal for me to try and put more content onto the blog page that's not blog content. does this make sense?

  7. Austin Matzko
    Member
    Posted 5 years ago #

    so, perhaps, i'm better off turning the front page into a static page. and then putting the the "blog" on another page. and then putting the "single recent post" on the static front page. logistically, does that make more sense given my desired end result?

    In my opinion, this is the best way to go, because otherwise you're going to run into some complicated paging issues.

  8. gallo
    Member
    Posted 5 years ago #

    ok, great. thanks. i'll give that a try and post back if/when i have more questions if that's alright. by the way i looked at your blog. very nice. also, i'm in boston too.

  9. gallo
    Member
    Posted 5 years ago #

    with otto's help i've decided to create a separate page template and put the 'recent post' code inside that php template.

    therefore, i have to do all of my coding for the rest of the page inside the php template.

    my problem now is that although it is calling up the correct "most recent post" it is not calling up the title, date, or meta information. it's just calling up my image and then the paragraph of text.

    here's my php page:

    <?php
    /*
    Template Name: Home
    */
    ?>
    
    <?php get_header(); ?>
    
    <div id="blog">
    
    <?php require_once (TEMPLATEPATH . '/navigation.php'); ?>
    
    	<div id="main">
    
    	<h2><?php the_title(); ?></h2>
    
    <?php
    query_posts(array('showposts' => 1));
    get_header(); ?>
    
    	<?php
    	global $dlPageId;
    	$dlPageId = null;
    	?>
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<?php $dlPageId = $post->ID; ?>
    			<?php the_content(); ?>
    	<?php endwhile; endif; ?>
    	<?php edit_post_link('Edit this entry.', '', '
    '); ?>
    	</div>
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>

    perhaps i have to edit my query code?

  10. You're calling get_header twice. Try this:

    <?php
    /*
    Template Name: Home
    */
    ?>
    
    <?php get_header(); ?>
    
    <div id="blog">
    
    <?php require_once (TEMPLATEPATH . '/navigation.php'); ?>
    
    	<div id="main">
    
    	<h2><?php the_title(); ?></h2>
    
    <?php query_posts('showposts=1');
          global $dlPageId;
          $dlPageId = null; ?>
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<?php $dlPageId = $post->ID; ?>
    			<?php the_content(); ?>
    	<?php endwhile; endif; ?>
    	<?php edit_post_link('Edit this entry.', '', ''); ?>
    	</div>
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>
  11. gallo
    Member
    Posted 5 years ago #

    thank you lpstenu.

    unfortunately that didn't work either. still no post title, date, or meta info.

    this is my work in progress if it helps:

    http://bcmediaproductions.com/site/

  12. gallo
    Member
    Posted 5 years ago #

    ignore/delete this box. mistake.

  13. Ah! Sorry, I was going after one of your problems, and not both :)

    Basically you've just got the_content() in there, but nothing else :) So all WP knows is to show the post.

    <?php
    /*
    Template Name: Home
    */
    ?>
    
    <?php get_header(); ?>
    
    <div id="blog">
    
    <?php require_once (TEMPLATEPATH . '/navigation.php'); ?>
    
    	<div id="main">
    
    	<h2><?php the_title(); ?></h2>
    
    <?php query_posts('showposts=1');
          global $dlPageId;
          $dlPageId = null; ?>
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<?php $dlPageId = $post->ID; ?>
                           <h2><?php the_title(); ?></a></h2>
                           <p class="postmetadata">Posted on <?php the_time('F jS, Y'); ?> at <?php the_time('g:i a'); ?> by <?php the_author_posts_link(); ?></p>
    			<?php the_content(); ?>
    	<?php endwhile; endif; ?>
    	<?php edit_post_link('Edit this entry.', '', ''); ?>
    	</div>
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>

    You'll need to figure out how you want the metadata and all to display, but there's a start.

  14. gallo
    Member
    Posted 5 years ago #

    you're great. thanks so much for the help.

    every time i learn something new i realize other things i can figure out on my own, which i prefer. but, it's really wonderful to have a place like this with such helpful people with some insight.

    thanks very much.

Topic Closed

This topic has been closed to new replies.

About this Topic