Member Avatar for T4gal

Hello,

Hopefully this is the right forum to post this on. I'm trying to include a few of the latest WP posts on an external homepage. The homepage is in the root folder of the website and WordPress is in it's own directory. I'm using WordPress 3.8.1 with a Twenty Thirteen child theme.

I've checked out the "Integrating WordPress with Your Website" codex page and as suggested there, I am using the following PHP to grab the header:

<?php
require('wp/wp-content/themes/bcv/header.php');
?>

But all it does is remove everything within the body and header tags so it gives me a blank page. If I change the path, it gives me an error saying no such file is found.

You can see what I'm talking about here:
http://www.berrycreekvet.com/home.php

What am I doing wrong?

Thanks in advance.

Hi,

I thought it should be like this

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

If you want to show your article, it can be written like this

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

<?php
$number_of_post = 5; ## change this value to your own needs
/*
*@order is for the database query Ascending or Descending sort method
*/
$order = 'ASC'; 

/*
*@ order_by
* post title is the column name of the wp_post table. 
* You can change this to several options e.g. post_date, etc..
*/
$order_by = 'post_title'; 

$posts = get_posts('numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) : setup_postdata( $post ); ?>
<?php the_date(); echo "<br />"; ?>
<?php the_title(); ?>    
<?php the_excerpt(); ?> 
<?php
endforeach;
?>

You can also copy and paste these codes from the codex as shown..

<?php
    require('Your_Wordpress_directory/wp-blog-header.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; ?>

Those PHP tags mixed-up are so tempting for correction, please don't do it. It is part of the Wordpress Syntax.

To acquire the theme style, just view the html source of your wordpress and use the css file url.

correction: update the $posts variable.

$posts = get_posts('numberposts='.$number_of_post.'&order='.$order.'&orderby='.$order_by);
Member Avatar for T4gal

Hello,

Thanks for the reply.

I don't understand, the first snippet you suggested looks exactly like mine except for the path? I obviously need to use the correct path to my actual files, right? Am I missing something?

Thanks!

The path should be the directory wherein the wordpress is installed. I believe that is an strict rule given by the wordpress codex.

Looking at your site, the reason it is blank because of this error

Call to undefined function language_attributes()

Try loading your page with all of the language_attribute() function commented just to see if the page will load properly.

I personally tested the above code snippets on the latest version of wordpress and it is working just the way I would expect them to work.

Member Avatar for T4gal

Finally got it working. The problem was I was linking to the wrong header file. I understood it as being the header.php file in the template folder, I hadn't realised that there was an actual file called wp-blog-header.php in the main wp directory.

I knew it was something simple I was missing. Thank you so much for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.