+ Reply to Thread
Results 1 to 10 of 10

 

Thread: Wordpress posts on non-wordpress page

  1. #1
    Registered User

    Status
    Offline
    Join Date
    Jan 2010
    Posts
    551
    Thanks
    32
    Thanked 42 Times in 34 Posts


    Hi guys,

    Ok - i am integrating wordpress with one of my sites and ahve come across a curious issue

    Basically I want to show the 3 latest blog posts on my sites homepage (which is outside of the WP installation - wordpress is sat in a directory called blog)

    Now - i have tried various methods such as:

    including the WP config within my sites homepage and looping through items:

    require_once('blog/wp-config.php');

    $news = $wpdb-get_results(SELECT ID,post_title FROM $wpdb-posts
    WHERE `post_type`=\post\ AND `post_status`= \publish\ ORDER BY `post_date` DESC LIMIT $how_many);
    foreach($news as $np){
    printf (lia href=\index.php?p=%s\%s/a/li, $np-ID,$np-post_title);
    }

    Also tried including the wp-load file and doing it that way:

    define('WP_USE_THEMES', false);
    require('blog/wp-load.php');

    <?php while (have_posts()): the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <?php the_excerpt(); ?>
    <p><a href="<?php the_permalink(); ?>">Read more...</a></p>
    <?php endwhile; ?>

    The curiopus thing is whenever I include or require ANY kind of WP file (wp-config, wp-load.php, wp-blog-header.php) I just get a blank white homepage - no errors no nothing??

    Any ideas or has anyone done something similar??

    I COULD just use simplepie to pull in a feed or simply access the WP database directly but this way seems a lot cleaner as it uses the WP classes and objects to access and handle the data

    I am using WP version 2.9.2

    Any ideas??

  2. #2
    pete_coles's Avatar
    Administrator

    Status
    Offline
    Join Date
    May 2007
    Posts
    513
    Thanks
    14
    Thanked 82 Times in 62 Posts
    The easiest way to do it would be to use your blogs feed and include it with an RSS parser. Haven't got tech details to hand but a quick google will sort ya!
    Jack of all trades master of some

  3. #3
    scriptmonkey's Avatar
    Oranges & Lemons

    Status
    Offline
    Join Date
    Jan 2009
    Location
    Worthing
    Posts
    1,581
    Thanks
    108
    Thanked 250 Times in 190 Posts
    This will do exactly what you want:

    Using your code and modifiying it so that it works

    Code:
    <?
    require_once('wp-config.php');
    global $wpdb;
    $news = $wpdb->get_results("SELECT ID,post_title FROM $wpdb->posts WHERE post_type='post' AND post_status= 'publish'
    						   ORDER BY post_date DESC LIMIT 3");
    foreach($news as $np){
    	printf ("<li><a href=\"index.php?p=%s\">%s</a></li>", $np->ID,$np->post_title); 
    }
    ?>

  4. #4
    scriptmonkey's Avatar
    Oranges & Lemons

    Status
    Offline
    Join Date
    Jan 2009
    Location
    Worthing
    Posts
    1,581
    Thanks
    108
    Thanked 250 Times in 190 Posts
    I have no idea what happened to the answer I posted here a few days ago, it must have been deleted, anyway, here's the answer:

    <?
    require_once('wp-config.php');
    global $wpdb;
    $news = $wpdb->get_results("SELECT ID,post_title FROM $wpdb->posts WHERE post_type='post' AND post_status= 'publish'
    ORDER BY post_date DESC LIMIT 3");
    foreach($news as $np){
    printf ("<li><a href=\"index.php?p=%s\">%s</a></li>", $np->ID,$np->post_title);

    }
    ?>

  5. #5
    Registered User

    Status
    Offline
    Join Date
    Jan 2010
    Posts
    551
    Thanks
    32
    Thanked 42 Times in 34 Posts
    Quote Originally Posted by scriptmonkey View Post
    I have no idea what happened to the answer I posted her a few days ago, it must have been deleted, anyway, here's the answer:

    <?
    require_once('wp-config.php');
    global $wpdb;
    $news = $wpdb->get_results("SELECT ID,post_title FROM $wpdb->posts WHERE post_type='post' AND post_status= 'publish'
    ORDER BY post_date DESC LIMIT 3");
    foreach($news as $np){
    printf ("<li><a href=\"index.php?p=%s\">%s</a></li>", $np->ID,$np->post_title);

    }
    ?>
    Exactly. But thats the problem.

    As soon as i require any worpress file (such as wp-config.php) I just get a blank white screen.....

    Even if i do no processing aftwerwards - just requiring the file gives a blank white screen?

  6. #6
    scriptmonkey's Avatar
    Oranges & Lemons

    Status
    Offline
    Join Date
    Jan 2009
    Location
    Worthing
    Posts
    1,581
    Thanks
    108
    Thanked 250 Times in 190 Posts
    So, the solution I gave doesn't work? Because, it works for me on 3 separate sites.
    Time passes. Listen. Time passes. Dylan Thomas
    Ebay Alerts to your inbox

  7. #7
    Registered User

    Status
    Offline
    Join Date
    Jan 2010
    Posts
    551
    Thanks
    32
    Thanked 42 Times in 34 Posts
    Quote Originally Posted by scriptmonkey View Post
    So, the solution I gave doesn't work? Because, it works for me on 3 separate sites.
    Correct. I am using the latest verison of WP though? So maybe a bug of some sorts?

  8. #8
    scriptmonkey's Avatar
    Oranges & Lemons

    Status
    Offline
    Join Date
    Jan 2009
    Location
    Worthing
    Posts
    1,581
    Thanks
    108
    Thanked 250 Times in 190 Posts
    I don't think it's a bug, you could try including wp-load.php instead of wp-config.php which will bypass all the template and header stuff that wp-config loads.

    Change the line to require_once('wp-load.php');

  9. #9
    Registered User

    Status
    Offline
    Join Date
    Jan 2010
    Posts
    551
    Thanks
    32
    Thanked 42 Times in 34 Posts
    Quote Originally Posted by scriptmonkey View Post
    I don't think it's a bug, you could try including wp-load.php instead of wp-config.php which will bypass all the template and header stuff that wp-config loads.

    Change the line to require_once('wp-load.php');
    I have tried everything. If i try and require or even require_once ANY WP file......(be it wp-header, wp-config, wp-load etc) then i just get a blank white screen

    It is very odd

  10. #10
    kickflip's Avatar
    Registered User

    Status
    Offline
    Join Date
    Oct 2008
    Location
    Stafford
    Posts
    255
    Thanks
    26
    Thanked 21 Times in 20 Posts
    Is the page you want to show them on in a different directory to wp-config? if so you would probably need to go (if wp-config is one directory above):
    require_once('../wp-config.php');

+ Reply to Thread


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. what to do with expired wordpress posts?
    By mightyone in forum Affiliate Marketing Lounge
    Replies: 7
    Last Post: 20-02-10, 11:04 PM
  2. wordpress - posts filed under question
    By keano in forum Programming
    Replies: 1
    Last Post: 03-08-09, 12:24 PM
  3. Convert CSV To Wordpress Posts Plugin
    By matty281k in forum Affiliate Marketing Lounge
    Replies: 6
    Last Post: 15-12-08, 11:02 PM
  4. Embedding Javascript into wordpress 2.3.1 posts
    By EyeOfTheTiger in forum Programming
    Replies: 3
    Last Post: 05-12-07, 10:54 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2