WordPress.org

Ready to get started?Download WordPress

Forums

Static Home Page to Include Latest Post (7 posts)

  1. Bezz333
    Member
    Posted 4 years ago #

    Hi all

    Slowly getting to grips with this coding stuff.

    I have made a static Home Page so I can add my own content but I would like to add the latest post on the page in the same post layout as it is displayed.

    How is it possible to do this?

    Andrew

  2. ronchicago
    Member
    Posted 4 years ago #

    one of my sites lists several topics and within each topic are five most recent posts. i won't be of much help as i did not personally write it. it is valid.

    here is the call for recent posts...

    <div class="main_block_rightcenter">
            <h1 class="recent_heads">Recent posts.</h1>
        	<?php
        		$querystr ="
          			SELECT DISTINCT $wpdb->posts.* FROM $wpdb->posts
          			WHERE $wpdb->posts.post_status = 'publish'
          			AND $wpdb->posts.post_type = 'post'
          			ORDER BY $wpdb->posts.post_date DESC
          			LIMIT 10";
    
          		$pageposts = $wpdb->get_results($querystr, OBJECT);
    
        		if ($pageposts) :
          			foreach ( $pageposts as $post ) :
            			?> <p class="recentpost"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></p> <?php
           			endforeach;
        		else :
      	  			echo ' ';
        		endif;
        	?>
        	</div>
        <!--end rightcenter-->

    here is what the "news" topic looks like...

    <div class="category">
            	<div class="category_img"><img src="home/resources/cat6.jpg" alt="News" /></div>
            	<div class="category_info"><a href="http://www.domain.com/category/news" title="News">News</a></div>
            	<div class="category_latest">
        			<?php
    					global $post;
    					$myposts = get_posts('numberposts=4&category=21');
    					foreach($myposts as $post) :
    						setup_postdata($post);
    				?>
    				<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    				<?php endforeach; ?>
            	</div>
    		</div>  <!--end category-->

    the code made the static page an rss page.

  3. Bezz333
    Member
    Posted 4 years ago #

    Ok, not too sure I have this right.

    Do I just past the above code into the 'Post' page in the dashboard as I get this if I do http://www.atthebench.com/

    Or do I have to enter it directly into the Home page? if I do Where do I find the Home page now as I have it set as a static page.

    i have looked at the index.php in the root directory but that does not seem to be the place

    As you can see I am a complete newb at this php coding.

  4. ronchicago
    Member
    Posted 4 years ago #

    i've never placed php in the admin and don't know if you even can. this is done on server via cpanel or whatever server admin tool your isp has set up for you. and i only show you the syntax and methodology on how to achieve your request.

    the code is put in the template of your static page within the <div>s you have. the needed functions and calls for files is in the above code but your personal files and category ID's have to be substituted. then you probably need custom css to further position it.

    i am sorry i can't help you further. i can read the php but not good enough to write this particular request.

  5. ronchicago
    Member
    Posted 4 years ago #

    maybe the top code may be enough for your needs for your recent posts. if you can just paste that in your static template and see what happens. i think you will see your recent posts but it probably won't look right.

    do you know how to give a div a class name and write the corresponding css to make it fit your theme ?

  6. Bezz333
    Member
    Posted 4 years ago #

    Yes, I know how ti sort out the div tags.

    I can not find the template for the static home page.

    This is usually index in html but it isn't in the templates.

    The Home page has a post number though.

    ?

  7. ronchicago
    Member
    Posted 4 years ago #

    some possibilities...

    1) your index may point you to ( name ) the static home page your looking for

    2) if your home page is a post pull it up on the browser and look at the source code to help you find your file.

    3) my home page does not have a post number/template. it's custom and is named menu2rss.php as the page looks like a menu. i instructed my isp to have menu2rss.php be the first file read rather than the index. if someone set up your home page and did the same thing contact your isp and they will give your file name.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.