As wordpress being a robust CMS system, usually people need to call their wordpress blog contents and posts in their existing websites. It has become an easy task using wordpress’ own code base and file structure.
Here is a simple tutorial which explains how can you get this done.
In order to call the contents of wordrpess blog, you will need to setup some basic stuff and call the required functions.
First of all, we have to call the blog header file which actually tells your PHP to call the initial variables of wordpress and makes the connection to its database automatically.
1 2 3 4 5 |
<?php /* Short and sweet */ define('WP_USE_THEMES', false); require('your-wordpress-installation-path/wp-blog-header.php'); ?> |
So the above file is necessary to be included in your php files. You will have to define the valid path to this file. The wp-blog-header.php file can be found on the root of wordpress installation.
After calling the header file, you can call functions of your installed wordpress blog. Below is a basic example of how you can list 10 posts of your blog in your webpage outside wordpress.
1 2 3 4 5 6 7 8 9 10 11 |
<?php $posts = get_posts('numberposts=10&order=ASC&orderby=post_title'); foreach ($posts as $post) : start_wp(); ?> <?php the_date(); echo " "; ?> <a title="Permanent Link to <?php the_title(); ?>" rel="bookmark" href="<?php the_permalink() ?>"><?php the_title(); ?></a> <?php the_excerpt(); ?> <?php endforeach; ?> |
In this example there are some basic functions of wordpress have been called.
the_date() function calls date of the post
the_permalink() function creates the full permanent link to the post in wordpress. This will also handle your permalink settings in the wordpress blog.
the_title() function displays the full title of the post
the_excerpt() function will display the excerpt of your post
There is a full article available for wordpress integration in your existing website and calling several functions outside wordpress. Integrating WordPress with Your Website