• Hi,
    I am trying to show the latest posts for a category(ies) on a non-wordpress site. I used to do this with a somple sql query but since the change to 2.3 I can’t do that any more.

    Instead, I have tried using:

    function showHeadlines($entrytype = '', $items = 4)
    {
      require('wordpress/wp-blog-header.php'); 
    
      $query = 'showposts=' . $items;
      if ($entrytype != '')
        $query .= '&cat=' . $entrytype;
    
      query_posts($query);
    
      if ($posts) : foreach ($posts as $post) : start_wp();
      $blogContent = get_the_content();
      ?>
          <a>'><?php the_time(’d/m/Y’); ?>: <?php the_title(); ?></a>\n";
          <small><?php add3dots(strip_tags($blogContent),"...",170)?></small>&nbsp;<a>'>Full Story: <?php the_title(); ?></a>
    
    ";
      <?php endforeach; else: ?>
      <?php endif; ?>
    <?}

    Where $entrytype is the comma list of cat id’s.

    I found this code on this forum, and on another site, both times it seems to have worked for the person asking, however I am getting an error:

    ‘Fatal error: Call to a member function hide_errors() on a non-object in /wordpress/wp-includes/functions.php on line 895’

    Can anybody help fix this, or suggest a better way? I don’t really want to use RSS as there is too much overhead with that.

    Thanks in advance.

    Tim

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi,

    I got over this hurdle the other day. Here’s what I did:

    Create a php file in your themes i.e. latest.php and put the below code in it:

    ———–

    <?php
    /*
    Template Name: Latest
    */
    ?>
    <?php
    global $post;
    $myposts = get_posts('numberposts=4&category=8');
    foreach($myposts as $post) :
    setup_postdata($post);
    ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php endforeach; ?>

    ———–

    numberposts=4&category=8
    Is simply what it says, how many posts you want displayed and from which category.

    Then create a page with no content in and call that i.e. latest-posts. Assign your latest.php as the template to be used.

    Then just create a PHP include on the page you want i.e.

    ———–

    <? include ("http://www.yourdomain.com/wordpress/latest-posts/");?>

    ———–

    Then it’s done!
    Matt

    Thread Starter lonewolfonline

    (@lonewolfonline)

    I’ll give that a try.

    Thanks!

    I’ll give that a try.

    Thanks!

    mqcarpenter

    (@mqcarpenter)

    This is great but you need URL file-access to make it work.

    mqcarpenter

    (@mqcarpenter)

    This is great but you need URL file-access to make it work.

    Try using “readfile” instead of “include,” if your host doesn’t let you include with a URL (mine doesn’t).

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WP Latest Posts in non-wordpress site’ is closed to new replies.