Help with posting blog excerpts on a non-WP page
-
Okay, first off thank you for any help you can provide.
Situation: I have a site that has both “static” and a wordpress install. The wordpress install is https://www.site.com/blog
What I am attempting to do is create a page that will actually be a widget that displays my latest 5 posts excerpts. I have searched the forum here and have found a number of suggested solutions. The only problem for me is that none of them seem to be working.
I think that this is my closest attempt at it:
<?php //required include files require('wp-blog-header.php'); require_once("wp-config.php"); require_once("wp-includes/wp-db.php"); ?> <?php $args = array( 'posts_per_page' => 5, 'order' => 'asc' ); $postslists = get_posts( $args ); foreach ( (array) $postslist as $post ) : setup_postdata( $post ); ?> <div> <?php the_date(); ?> <br /> <?php the_title(); ?> <?php the_exercpt(); ?> </div> <?php endforeach; wp_reset_postdata(); ?>
This file is in the ../blog folder. The only problem is that it returns a blank screen.
My other attempt at this is (again in the /blog folder):
<?php /* Short and sweet */ define('WP_USE_THEMES', false); require('wp-blog-header.php'); ?> <?php global $post; $args = array( 'posts_per_page' => 3 ); $myposts = get_posts( $args ); foreach( $myposts as $post )?: setup_postdata($post);??> <a href="<?php the_permalink()??>" rel="bookmark" title="Permanent Link to <?php the_title_attribute();??>"> <?php the_title();??></a><br /> <?php endforeach;??>
Which provides me with an error : Parse error: syntax error, unexpected ‘:’
Anyone have any advice, suggestions, comments, or condescending scorned looks?
Thanks in advance.
- The topic ‘Help with posting blog excerpts on a non-WP page’ is closed to new replies.