WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display Title and Excerpt on a page outside of WordPress (5 posts)

  1. mactoph
    Member
    Posted 8 years ago #

    I think the way that I need to do this is to create a file that would write the title and excerpt of a post to a file that I could then include from another page, but I've tried a couple of ways to do that and am not having any luck?!
    I want just the title and excerpt without any of the surrounding template-
    I came up with this code that I think is right:
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <h2><?php the_title(); ?></h2><br />
    <?php _e("Posted on "); ?><?php the_time('l j F Y',display); ?>

    <?php the_excerpt(); ?>

    <?php endwhile; else: ?><br />
    <?php _e('Sorry, no posts matched your criteria.'); ?><br />
    <?php endif; ?>

    but I'm not sure where to put it?- any help or better way of doing this?

  2. Kafkaesqui

    Posted 8 years ago #

    It doesn't matter where you put The Loop. What does matter is that A. the file you're putting it in is a PHP file, and B. You're including the wp-blog-header.php file at some point before it, like so:

    <?php require('./blog/wp-blog-header.php'); ?>

    Just make sure the path to it is correct.

  3. mactoph
    Member
    Posted 8 years ago #

    Thanks!!

  4. moshu
    Member
    Posted 8 years ago #

    The way you want to go sounds a bit complicated: create a file that would have the title and excerpt, then include the file into another file...
    Why not pu the Loop directly into the "final" file?
    See also my (unfinished) tutorial about displaying WP in another webpage.

  5. witchy
    Member
    Posted 7 years ago #

    Moshu! THANK YOU! Using your tutorial, and a few suggestions/advice from a couple of others here at the forum, my blog is now doing EXACTLY what I want it to do.

    I write in the blog /which is in it's own folder/ and an excerpt shows up on my main root index. THANK you for the step by step (with pictures!) instructions. It was so helpful to see exactly what code I was suppose to be grabbing.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.