WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Insert blog posts on index.php outside WP directory (12 posts)

  1. kaistarr
    Member
    Posted 6 years ago #

    Hi, everybody! I would like to find out how to insert my most recent blog posts into an index.php page that is outside of the WordPress directory. I've tried the suggestion in this post: http://wordpress.org/support/topic/149637 and it didn't work for me. It just returns a blank page. Right now, I'm inserting the posts using RSS, but this is a less-than-ideal solution, as I can't figure out how to have it show the number of comments.

    Here's the page where I'm wanting to insert the posts, and you can see how it ends up with RSS feeding it in: http://www.kaistarr.com/

    Anyone have any ideas on how I can make this work without RSS? I'm currently running 2.3.2 but will update to 2.3.3 this weekend, when I've had a chance to backup my database.

    I appreciate any help!

  2. rondelw
    Member
    Posted 6 years ago #

    has there been any headway on thsi issue?

  3. kaistarr
    Member
    Posted 6 years ago #

    Nope, I never did figure it out or get anything to work. And since I can't get the comments to show in the feed on the index page, nobody comments...except spammers. I guess people don't want to have to go to a second page, just to read or post comments. So my plan now is to just take down the WordPress blog and do my index-page blogging by hand, in an include or something. Shame, because I really liked the WP setup. I just can't get it to do what I need it to do.

  4. rawalex
    Member
    Posted 6 years ago #

    I have done it on a site I run, but I cannot show you because it is "adult oriented" and whooami will have a little fit.

    Basically, it's just pure database work. write a php program that opens the wordpress database, select from wp_posts where status is active and order by post date (and limit it to the number you need), and then step through them one after another... post title, post content, etc is all there.

    good luck with it.

  5. kaistarr
    Member
    Posted 6 years ago #

    Thanks for the advice, rawalex! I'm very inexperienced with php, though. This might be a bit beyond me, but I'm willing to learn and try it.

  6. Anonymous
    Unregistered
    Posted 5 years ago #

    kaistarr here is something that has worked for me on 3 sites.

    1. find and download MtDewVirus recent post plug in
    2. create a file with these contents and name it nav_include.php

    `<?php
    define('WP_USE_THEMES', false);
    require('/var/www/html/blog/wp-blog-header.php');
    ?>
    <?php mdv_recent_posts(5, ' ', '<hr>'); ?>

    3. be sure to change your root path directory, ie, /var/www blah blah blah.
    4. put nav_include.php in your current theme's directory
    5. include that file anywhere you want, eg, outside the blog.

    A guy name Nate showed this too me.

  7. kaistarr
    Member
    Posted 5 years ago #

    Thanks, Peter! I'll try that as soon as I get a chance, this week, and then post about whether or not I managed to screw it up, somehow. :P

  8. bplank
    Member
    Posted 5 years ago #

    yup... this is all you need in the index.php file:

    <?php
    define('WP_USE_THEMES', true);
    require('./FOLDER-WHERE-YOU-WISH-TO-LOAD-THE-SITE-FROM/wp-blog-header.php');
    ?>
  9. Chris_K
    Member
    Posted 5 years ago #

    Check the "Integrating" section on Creating_a_Static_Front_Page for more.

  10. kaistarr
    Member
    Posted 5 years ago #

    Thanks for all the help, guys! My life has been really hectic, lately, so I haven't had the time to try these things out, yet, but I will. Anyway, you rock! \(^o^)/

  11. kaistarr
    Member
    Posted 5 years ago #

    Well, after having tried everything here, I still can't get anything to do what I had hoped it would do. I can get it to produce a linked list of the titles of the most recent posts, but that's not what I'm after.

    What I'm after is just one step more than I'm already doing with RSS, which is to have it show the comment status. I've already got it showing the linked title, full post content, time of post, and a hand-made link to the post's specific WP page (followed by a divider image of my own), but I can't for the life of me figure out how to add in the comment status, with the number of comments each post has, at the end of the post's page link.

    This is what I've got that is working for me, except for that one thing, the comment status:

    <?php
    define('MAGPIE_DIR', 'magpierss/');
    require_once(MAGPIE_DIR.'rss_fetch.inc');
    define('MAGPIE_CACHE_ON', 0);
    
    $url = 'http://www.kaistarr.com/wordpress/?feed=rss2';
    
    if ( $url ) {
    	$rss = fetch_rss( $url );
    	echo "<div style=color:#000; width:420px; padding-left:30px; margin-bottom:20px; border-bottom: dashed 1px #000;>";
    	foreach ($rss->items as $item) {
    		$href = $item['link'];
    		$title = $item['title'];
    		$description = $item['description'];
    		$summary = $item['summary'];
    		$content = $item['atom_content'];
    		$encoded = $item['encoded'];
    		$date = $item['pubdate'];
    
    		echo "<h3><a href=$href>$title</a></h3>";
    		echo "$content";
    		echo "$encoded";
    		echo "<small><i>$date</small></i>";
    		echo "<i>Read or Add Comments on <a href=$href>$title</a></i><center><img src=http://www.kaistarr.com/stories/skins/rawhide/images/horizontalrule_brown.png></center>";
    	}
    	echo "</div>";
    }
    ?>

    I had

    $comments = $item['comments'];

    and

    echo "<a href=$href>$comments</a>";

    in there, at first, instead of my "read or add comments..." code, and it returned just a linked line that displayed the URL to that specific post, with the #comments added on the end. Not very pretty.

    Is there something really simple that I'm missing, or is there simply no way to do what I want to do, outside of the WP directory? I can live with what I've already got it doing, but I'd sure like to have the comment status on there, too.

    Thanks, again, for all the help you guys have given me. I'm sorry to be such a pest!

  12. kaistarr
    Member
    Posted 5 years ago #

    Well, I have resolved this unresolvable problem by removing the WP from my site. My WP was under constant hacker attacks, anyway, so I guess it's no great loss. Sorry, guys. I really wanted it to work for me, but it just didn't. Thanks to all those who tried to help me. I do appreciate your time and effort!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.