Seattle Web Design
Blog > How to display latest posts on a non-WordPress page of your website

Meet the author:
Jill Olkoski

Jill has a MA in Clinical Psychology, a BS in Computer Science, and a BS in Mechanical Engineering.

She currently owns Aldebaran Web Design in Edmonds (near Seattle WA) and enjoys educating her clients on topics related to small business website design.

In Jill's previous life, she spent 17 years in the engineering and quality organizations of a Fortune 100 tech company.

 


How to display latest posts on a non-WordPress page of your website

January 28th, 2015

Sometimes websites have a WordPress blog installed in a sub directory, and you want to display the most recent posts on a page of the website that is not part of WordPress.

Here’s the PHP Code to do this.

Just put this inside a div and replace the path that’s after the require function to the full path of where ever your wordpress header file is.

<?php
define(‘WP_USE_THEMES’, false);
require(‘/home/something/yourwebsite.com/yourdirectory/wp-blog-header.php’);

// changes excerpt length from the default 55 to 20
function custom_excerpt_length( $length ) {
return 20;
}
add_filter( ‘excerpt_length’, ‘custom_excerpt_length’, 999 );
//*****************

// changes the default exerpt […] to a read more
function new_excerpt_more( $more ) {
return ‘…<em><a class=”read-more” href=”‘. get_permalink( get_the_ID() ) . ‘”>more</a></em>’;
}
add_filter( ‘excerpt_more’, ‘new_excerpt_more’ );
//*******************

global $post;
$args = array( ‘posts_per_page’ => 3 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :    setup_postdata($post); ?>
<div class=”blogpost”><strong><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></a></strong><br /><?php the_excerpt(); ?></div> <br />
<?php endforeach;
?>

Jill
--------------
J. Olkoski
Aldebaran Web Design, Seattle
Jill Olkoski has a BS in Engineering, a BS in Computer Science and an MA in Clinical Psychology. She delights in using her advanced technical and psychological skills to help small business owners develop cost-effective and successful websites.



Comments are closed.



 ©2006 - © Aldebaran Web Design Seattle, A DBA of Aldebaran Services LLC
Search Blog Articles: