WordPress.org

Ready to get started?Download WordPress

Forums

[closed] Add a Latest News sidebar in a Static HTML home page? (3 posts)

  1. Chastepe
    Member
    Posted 11 months ago #

    Hi everyone, before I begin I would like you to know that I am new to WordPress.

    I am developing a web site which consists of static web pages in html. However I have created a dynamic page using WordPress for the news section. It works fine so far but the news page is not the first page someone sees when he visits the web site. Instead I have an "index.html" web page where it welcomes and describes what the website is about. So I would like to make my home page more interesting by adding a sidebar where the latest blog posts-news will be displayed ideally in a list of titles. As you may know all the static - html web pages are located in the root directory while news web page is located inside WordPress' themes directory named index.php. My WordPress theme has only four sections footer, header, index and style.css.

    So far I found a piece of code which I added in the index.php (News Page) of my theme's WordPress directory but it displays the latest posts only in that page.

    My question is how could I import this piece of code inside my home page which is in html? Is there a way to "inject" this code in a static web page that is located outside WordPress' directory?

    *I tried renaming my welcome page: index.html into index.php - home.php and then I added the same php code inside a div hoping to display the latest posts but I had no luck.

    Here is the code I found on another thread:

    <?php if( is_front_page() ) { ?>
    <div class="latestnews">
    <h1>Latest News</h1>
    <ul class="latest-news">
    <?php
     global $post;
     $myposts = get_posts('numberposts=3');
     foreach($myposts as $post) :
     ?>
        <li><span class="post-info"><?php the_title(); ?><br/><?php the_time('F jS, Y'); ?></span><a href="<?php the_permalink(); ?>"></a></li>
     <?php endforeach; ?>
    </ul>
    </div>
    	<?php } ?>
  2. Rod Whiteley
    Member
    Posted 11 months ago #

    If the static page is just HTML, not PHP, then I think you need an iframe in the static page to load a WordPress PHP page. In WordPress you can create a template that displays the latest news the way you want it to appear in the iframe. (I assume the theme is your own.)

    Personally, I'm surprised that you are using separate HTML pages instead of using WordPress for the entire site.

  3. Chastepe
    Member
    Posted 11 months ago #

    Thanks a lot, I will try to find out what is and how to use an iframe. Yes as you correctly assumed I have designed the layout.

    The reason I did not begin to code it in WordPress from the beginning is, first of all I had no experience with it before and I thought it would be difficult and complex to design and tweak my layout. Secondly the website consists of 9 static web pages and 1 dynamic. So I was thinking that I could create my own php dynamic page as it is only one but I had never done that before and I realised that it would be time consuming. Then I learned about WordPress and its CMS capabilities.

Topic Closed

This topic has been closed to new replies.

About this Topic