<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Show recent WordPress posts in Laravel Archives - Artificial Intelligence</title>
	<atom:link href="https://www.aiuniverse.xyz/tag/show-recent-wordpress-posts-in-laravel/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.aiuniverse.xyz/tag/show-recent-wordpress-posts-in-laravel/</link>
	<description>Exploring the universe of Intelligence</description>
	<lastBuildDate>Tue, 10 Sep 2024 13:33:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>How to Display Recent WordPress Posts in a Laravel Application</title>
		<link>https://www.aiuniverse.xyz/how-to-display-recent-wordpress-posts-in-a-laravel-application/</link>
					<comments>https://www.aiuniverse.xyz/how-to-display-recent-wordpress-posts-in-a-laravel-application/#respond</comments>
		
		<dc:creator><![CDATA[Maruti Kr.]]></dc:creator>
		<pubDate>Tue, 10 Sep 2024 13:33:27 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Display WordPress posts in Laravel]]></category>
		<category><![CDATA[Fetch WordPress posts in Laravel]]></category>
		<category><![CDATA[Guzzle fetch WordPress posts]]></category>
		<category><![CDATA[Laravel blog integration]]></category>
		<category><![CDATA[Laravel display WordPress content]]></category>
		<category><![CDATA[Laravel WordPress API]]></category>
		<category><![CDATA[Show recent WordPress posts in Laravel]]></category>
		<category><![CDATA[WordPress API Laravel tutorial]]></category>
		<category><![CDATA[WordPress Laravel integration]]></category>
		<category><![CDATA[WordPress REST API Laravel]]></category>
		<guid isPermaLink="false">https://www.aiuniverse.xyz/?p=19117</guid>

					<description><![CDATA[<p>To display recent WordPress posts in a Laravel page, you&#8217;ll need to interact with the WordPress database or use the WordPress REST API. Here&#8217;s a simple approach <a class="read-more-link" href="https://www.aiuniverse.xyz/how-to-display-recent-wordpress-posts-in-a-laravel-application/">Read More</a></p>
<p>The post <a href="https://www.aiuniverse.xyz/how-to-display-recent-wordpress-posts-in-a-laravel-application/">How to Display Recent WordPress Posts in a Laravel Application</a> appeared first on <a href="https://www.aiuniverse.xyz">Artificial Intelligence</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="1024" height="1024" src="https://www.aiuniverse.xyz/wp-content/uploads/2024/09/DALL·E-2024-09-10-19.01.39-A-modern-tech-style-illustration-showing-the-integration-of-WordPress-and-Laravel-with-icons-of-WordPress-and-Laravel-connected-through-an-API-symbol.webp" alt="" class="wp-image-19119" srcset="https://www.aiuniverse.xyz/wp-content/uploads/2024/09/DALL·E-2024-09-10-19.01.39-A-modern-tech-style-illustration-showing-the-integration-of-WordPress-and-Laravel-with-icons-of-WordPress-and-Laravel-connected-through-an-API-symbol.webp 1024w, https://www.aiuniverse.xyz/wp-content/uploads/2024/09/DALL·E-2024-09-10-19.01.39-A-modern-tech-style-illustration-showing-the-integration-of-WordPress-and-Laravel-with-icons-of-WordPress-and-Laravel-connected-through-an-API-symbol-300x300.webp 300w, https://www.aiuniverse.xyz/wp-content/uploads/2024/09/DALL·E-2024-09-10-19.01.39-A-modern-tech-style-illustration-showing-the-integration-of-WordPress-and-Laravel-with-icons-of-WordPress-and-Laravel-connected-through-an-API-symbol-150x150.webp 150w, https://www.aiuniverse.xyz/wp-content/uploads/2024/09/DALL·E-2024-09-10-19.01.39-A-modern-tech-style-illustration-showing-the-integration-of-WordPress-and-Laravel-with-icons-of-WordPress-and-Laravel-connected-through-an-API-symbol-768x768.webp 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>To display recent WordPress posts in a Laravel page, you&#8217;ll need to interact with the WordPress database or use the WordPress REST API. Here&#8217;s a simple approach using the WordPress REST API to fetch the latest posts and display them on your Laravel page.</p>



<h3 class="wp-block-heading">Step 1: Fetch WordPress Posts Using REST API</h3>



<p>First, WordPress offers a REST API that you can use to fetch recent posts. The URL to get the latest posts is typically:</p>



<pre class="wp-block-code"><code>https:&#47;&#47;your-wordpress-site.com/wp-json/wp/v2/posts</code></pre>



<p>You can use Laravel&#8217;s HTTP client to fetch data from this API.</p>



<h3 class="wp-block-heading">Step 2: Make an HTTP Request in Laravel</h3>



<ol class="wp-block-list">
<li><strong>Install Guzzle</strong> (Laravel 8+ uses Guzzle by default, but if you&#8217;re on an older version, you may need to install it):</li>
</ol>



<pre class="wp-block-code"><code>   composer require guzzlehttp/guzzle</code></pre>



<ol start="2" class="wp-block-list">
<li><strong>Create a Controller Method to Fetch Posts</strong>: Inside your Laravel controller, add a method to fetch and display the WordPress posts:</li>
</ol>



<pre class="wp-block-code"><code>   &lt;?php

   namespace App\Http\Controllers;

   use Illuminate\Http\Request;
   use Illuminate\Support\Facades\Http;

   class BlogController extends Controller
   {
       public function showRecentPosts()
       {
           // Fetch the latest posts from the WordPress REST API
           $response = Http::get('https://your-wordpress-site.com/wp-json/wp/v2/posts');

           // Check if the request was successful
           if ($response-&gt;successful()) {
               // Get the posts data
               $posts = $response-&gt;json();
           } else {
               $posts = &#91;];
           }

           // Pass the posts data to a view
           return view('blog.recent-posts', compact('posts'));
       }
   }</code></pre>



<h3 class="wp-block-heading">Step 3: Create a View to Display the Posts</h3>



<p>Create a view (e.g., <code>resources/views/blog/recent-posts.blade.php</code>) to display the posts:</p>



<pre class="wp-block-code"><code>@extends('layouts.app')

@section('content')
    &lt;div class="container"&gt;
        &lt;h1&gt;Recent WordPress Posts&lt;/h1&gt;
        @if(!empty($posts))
            @foreach($posts as $post)
                &lt;div class="post"&gt;
                    &lt;h2&gt;{{ $post&#91;'title']&#91;'rendered'] }}&lt;/h2&gt;
                    &lt;div&gt;{!! $post&#91;'excerpt']&#91;'rendered'] !!}&lt;/div&gt;
                    &lt;a href="{{ $post&#91;'link'] }}" target="_blank"&gt;Read more&lt;/a&gt;
                &lt;/div&gt;
                &lt;hr&gt;
            @endforeach
        @else
            &lt;p&gt;No posts available.&lt;/p&gt;
        @endif
    &lt;/div&gt;
@endsection</code></pre>



<h3 class="wp-block-heading">Step 4: Define a Route for Displaying Posts</h3>



<p>In your <code>routes/web.php</code> file, define a route for this:</p>



<pre class="wp-block-code"><code>use App\Http\Controllers\BlogController;

Route::get('/recent-posts', &#91;BlogController::class, 'showRecentPosts']);</code></pre>



<h3 class="wp-block-heading">Step 5: Test the Page</h3>



<p>Now, when you visit <code>/recent-posts</code> in your Laravel application, it should display the recent posts from your WordPress site.</p>



<h3 class="wp-block-heading">Customization</h3>



<p>You can customize the way the posts are fetched, including limiting the number of posts by adding query parameters to the API request:</p>



<pre class="wp-block-code"><code>https:&#47;&#47;your-wordpress-site.com/wp-json/wp/v2/posts?per_page=5</code></pre>



<p>This will limit the results to the 5 most recent posts.</p>



<p>That&#8217;s it! You now have a Laravel page showing recent WordPress posts using the REST API.</p>
<p>The post <a href="https://www.aiuniverse.xyz/how-to-display-recent-wordpress-posts-in-a-laravel-application/">How to Display Recent WordPress Posts in a Laravel Application</a> appeared first on <a href="https://www.aiuniverse.xyz">Artificial Intelligence</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.aiuniverse.xyz/how-to-display-recent-wordpress-posts-in-a-laravel-application/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
