Access and display Wordpress messages from Wordpress

I have a commercial website (php) and have a Wordpress blog in a subdirectory. I need to display the latest posts on a homepage that is outside of Wordpress: /

website: http://www.blabla.com

blog: http://www.blabla.com/blog/

Therefore, I need to display messages at www.blabla.com/index.php. How can I access Wordpress features?

Thanks a lot! estimate!

+3
source share
4 answers

The easiest way is to use your Wordpress RSS feed.

Download it with file_get_contents()or cURL for more control.

simpleXML .

, -... APC PEAR:: Cache_Lite.

: ( - , ):

$xmlText = file_get_contents('http://www.blabla.com/blog/feed/');

$xml = simplexml_load_string($xmlText);

foreach ($xml->item as $item)
{
    echo 'Blog Post: <a href="' . htmlentities((string)$item->link) . '">'
        . htmlentities((string)$item->title) . '</a>';

    echo '<p>' . (string)$item->description . '</p>';
}
+2

WordPress, wp-blog-header.php, wp-load.php, .

WP_Query get_posts ( ). WP_Query The Loop WordPress. , - WordPress, - , GET.

, WP_Query:

<?php
$my_query = new WP_Query('showposts=3');
while ($my_query->have_posts()): $my_query->the_post();
?>
<h1><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h1>
<?php endwhile; ?>

, get_posts():

<?php
global $post;
$posts = get_posts('showposts=3');
foreach($posts as $post) :
?>
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<?php endforeach; ?>

, !:)

+2

hey just found a solution online;

http://www.corvidworks.com/articles/wordpress-content-on-other-pages

works great!

<?php
// Include Wordpress 
define('WP_USE_THEMES', false);
require('blog/wp-blog-header.php');
query_posts('showposts=3');


?>      
<?php while (have_posts()): the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php endwhile; ?>  
+1
source

I think the easiest solution is to receive messages directly from the database.

-1
source

Source: https://habr.com/ru/post/1718270/


All Articles