How to use WordPress functions/posts outside the WordPress directory



Many of us (webmasters) will try develop an app/extension for chrome or any such to showcase the great contents from the website. So in a way one has to develop from scratch, which is time consuming !. To cut short, you can straight away use your WordPress  functions and posts directly which i will be showing you how to use WordPress functions and posts outside the WordPress directory.

Features :

Coding time reduces
Maintenance will be easy
Duplicity in coding will be reduced
wordpress functions and posts outside wordpress directory

wordpress functions and posts outside wordpress directory

Non-Responsive Facebook like POPOVER on Hover using only CSS and no Javascript/JqueryNon-Responsive Facebook like POPOVER on Hover using only CSS and no Javascript/Jquery

How to include WordPress ?

The key to use WordPress outside the WordPress directory is wp-load.php or wp-blog-header.php file. If you don’t want the WordPress themes, define it to “false”.

define('WP_USE_THEMES', false);
require_once('Absolute Path to wp-load.php');

How to access WordPress functions ?

Once the wp-load.php file is included, the entire WordPress functions is provided to you. Here i will be showing you obtaining recent posts using WordPress functions by running through loop.

$postslist = get_posts($args);
foreach($postslist as $post) {
setup_postdata($post);
 $the_title = get_the_title();
 $the_link = get_permalink();
 $the_content = get_the_excerpt();
 print "<a href="$the_link">$the_title</a>";
 print "<div class='title'>$the_content</div>";
}

Here am getting the title, link and the excerpt content of the post and printing it.

Non-Responsive Facebook like POPOVER on Hover using only CSS and no Javascript/JqueryNon-Responsive Facebook like POPOVER on Hover using only CSS and no Javascript/Jquery

Topics :

Disclaimer: The content published in this article is the views of the author only. Techglimpse does not gurantee accuracy, completness or validity. If you believe the content on this post violates your copyright, please send us a mail to [email protected] for removal. Read more.