I have never used WordPress before, so please forgive my naivety...
I have built a bespoke website that is not currently managed by WordPress. For SEO purposes and to announce special offers etc, my client would like to add a News Feed to the site. To save me having to write a bespoke CMS for a single page, I would like to implement WordPress on just this particular page.
I am currently very confused as to how WordPress works as, believe it or not, there is too much information on the net and resultantly I am just left baffled...
I was therefore hoping that someone may be able to answer a few of my queries, thus pointing me in the right direction for creating this WordPress powered News Feed.
Here are my questions:
wp_*
functions, is there documentation for these?httpdocs/
, should I be placing WordPress into httpdocs/wp/
?Please note, I am not asking you to write the code for me, I simply need pointing in the right direction.
I have now installed and configured WordPress... However, I am still having issues with particular things in WordPress.
At the moment WordPress is installed in a sub directory, I have configured this within General Settings so WordPress is aware. I have done this because I do not want all the WordPress files in my root directory for the sake of a simple News Feed!
That said, I now have the following issues:
Once I have worked out, with the help of Stackoverflow, the above, I will then be able to proceed to using the WordPress functions to gather my feeds from the database. In the meantime, I simply want to get the above sorted...
To utilize WordPress
's functionality you can use WordPress
as a function library, for example, you can include WordPress
in any page on your site using
<?php
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
?>
This is wp-blog-header.php
if ( !isset($wp_did_header) ) {
$wp_did_header = true;
require_once( dirname(__FILE__) . '/wp-load.php' );
wp();
require_once( ABSPATH . WPINC . '/template-loader.php' );
}
This will, do the rest for you but keep the complete WordPress
in your site's root.
This is an example that is outside of WordPress
$posts = get_posts('numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) : start_wp();
the_date(); echo "<br />";
the_title();
the_excerpt();
endforeach;
Update: (for a custom feed you can use)
<?php
if(function_exists('fetch_feed')) {
// change the url where you put the file,
// also it may has dependency on otherfiles, so make sure about it.
include_once(ABSPATH . WPINC . '/feed.php');
$feed = fetch_feed('feedurl');
$limit = $feed->get_item_quantity(5);
$items = $feed->get_items(0, $limit);
}
if ($limit == 0) echo '<div>The feed is either empty or unavailable.</div>';
else {
?>
<ul style="margin-bottom:10px">
<?php foreach ($items as $item) : ?>
<li>
<a target="_blank" href="<?php echo $item->get_permalink(); ?>" alt="<?php echo $item->get_title(); ?>"><?php echo $item->get_title(); ?></a>
<small style="color:gray;display:block;"><?php echo $item->get_date('jS F Y'); ?></small>
</li>
<em><?php echo $item->get_date('j F Y'); ?></em>
<p><?php echo substr($item->get_description(), 0, 200); ?> ...</p>
<?php endforeach; ?>
</ul>
<?php } ?>
P/S: This code is taken from one of my sites, so please adjust it. Also check Codex.