• I am trying to add my latest blog posts to my homepage. I am placing the following code on my homepage:

    <?php
    require(‘/myblog/wp-blog-header.php’);
    ?>

    <?php
    $posts = get_posts(‘numberposts=5&order=ASC&orderby=post_title’);
    foreach ($posts as $post) : start_wp(); ?>
    ” rel=”bookmark” title=”Permanent Link to<?php the_title(); ?>”><?php the_title(); ?>
    <?php the_excerpt(); ?>
    <?php
    endforeach;
    ?>

    This does not seem to be working as all that is appearing on my homepage where the posts should be is ” rel=”bookmark” title=”Permanent Link to”>

    Can anyone see what I maybe doing wrong or the reason for this.

    Thanks in advance

Viewing 6 replies - 1 through 6 (of 6 total)
  • <?php
    $args=array(
      'orderby' => 'title',
      'order' => 'ASC',
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 5,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of 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
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
    Thread Starter lab75

    (@lab75)

    Thanks but I tried using this code and it is still not working. The code is still being displayed on the page.

    what is the name of your home page?

    is it something.html? you have to change the extension by renaming it to something.php for that code to work

    (Start with the simplest issues)

    Thread Starter lab75

    (@lab75)

    Homepage is index.html – Will changing the extension to .php affect my page rank? If so, Is there any other way of getting this to work?

    What RVoodoo said!,

    plus, this require(‘/myblog/wp-blog-header.php’); may need some ‘correcting’

    You can ignore my example above if your example works.

    I have no idea about page rank stuff…..but .php extension is required if you want to have php code actually function.

    Otherwise, you can look at using some sort of rss feed, or if you feel real frisky, you can use an xslt fragment (it’s what I used to use, it’s a pain). But either of these 2 solutions really kill your options as far as styling, etc go

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding latest blog posts to homepage’ is closed to new replies.