Home Property Listings
Home Property Listings
1. Create a Dedicated Component for Home Page Listings
a. Set Up the Component File
b. Import Required Modules and Data
"use client"; import PropertyCard from '@/components/PropertyCard'; import properties from '@/properties.json'; // Adjust path if needed import Link from 'next/link';
c. Randomize and Select Recent Listings
//components/HomeProperties.jsx import properties from '@/properties.json' import PropertyCard from './PropertyCard' import Link from 'next/link' const HomeProperties = () => { // Randomize the array using sort with Math.random, then select the first three properties const recentProperties = properties .sort(() => Math.random() - Math.random()) .slice(0, 3) return ( // <!-- Recent Properties --> <section className="px-4 py-6"> <div className="container-xl lg:container m-auto"> <h2 className="text-3xl font-bold text-blue-500 mb-6 text-center"> Recent Properties </h2> <div className=""> {recentProperties.length === 0 ? ( <p className="text-center">No properties found.</p> ) : ( <div className="grid grid-cols-1 md:grid-cols-3 gap-6"> {recentProperties.map((property) => ( <PropertyCard key={property._id} property={property} /> ))} </div> )} </div> </div> {/* Button to view all properties */} <div className="mt-10 flex justify-center"> <Link href="/properties" className="bg-black text-white text-center py-4 px-6 rounded-xl hover:bg-gray-700"> View All Properties </Link> </div> </section> ) } export default HomeProperties
2. Integrate the HomeProperties Component into the Home Page
a. Open Your Home Page File
b. Import and Insert the Component
3. Testing and Refinements
a. Run the Development Server
b. Adjust and Refine
Recap
Last updated