YouTube Video Gallery with Pagination & Hover Effects
I'll create a responsive YouTube video gallery for WordPress that displays videos in a grid with pagination and hover effects. The solution will use pure HTML, CSS, and JavaScript without external dependencies.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>YouTube Video Gallery - WordPress Style</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
color: #fff;
padding: 20px;
min-height: 100vh;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
header {
text-align: center;
margin-bottom: 40px;
padding: 20px;
}
h1 {
font-size: 2.8rem;
margin-bottom: 10px;
background: linear-gradient(to right, #ff416c, #ff4b2b);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.subtitle {
font-size: 1.2rem;
color: #a0a0c0;
max-width: 700px;
margin: 0 auto;
line-height: 1.6;
}
.video-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
gap: 25px;
margin-bottom: 40px;
}
.video-card {
background: rgba(30, 30, 50, 0.7);
border-radius: 12px;
overflow: hidden;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
transition: all 0.4s ease;
position: relative;
}
.video-card:hover {
transform: translateY(-10px);
box-shadow: 0 15px 35px rgba(255, 75, 43, 0.3);
background: rgba(40, 40, 60, 0.8);
}
.video-thumb {
position: relative;
height: 200px;
overflow: hidden;
}
.video-thumb img {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.5s ease;
}
.video-card:hover .video-thumb img {
transform: scale(1.1);
}
.play-icon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 70px;
height: 70px;
background: rgba(255, 75, 43, 0.85);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
opacity: 0.9;
transition: all 0.3s ease;
}
.play-icon i {
color: white;
font-size: 28px;
margin-left: 5px;
}
.video-card:hover .play-icon {
background: rgba(255, 65, 108, 0.95);
transform: translate(-50%, -50%) scale(1.1);
}
.video-duration {
position: absolute;
bottom: 10px;
right: 10px;
background: rgba(0, 0, 0, 0.7);
padding: 3px 8px;
border-radius: 4px;
font-size: 0.85rem;
}
.video-info {
padding: 20px;
}
.video-title {
font-size: 1.2rem;
margin-bottom: 10px;
line-height: 1.4;
color: #fff;
transition: color 0.3s ease;
}
.video-card:hover .video-title {
color: #ff4b2b;
}
.video-meta {
display: flex;
justify-content: space-between;
color: #a0a0c0;
font-size: 0.9rem;
}
.pagination {
display: flex;
justify-content: center;
margin-top: 30px;
gap: 10px;
}
.page-numbers {
display: flex;
gap: 8px;
}
.pagination button {
background: rgba(50, 50, 70, 0.7);
color: #fff;
border: none;
width: 40px;
height: 40px;
border-radius: 8px;
cursor: pointer;
transition: all 0.3s ease;
font-weight: 600;
display: flex;
align-items: center;
justify-content: center;
}
.pagination button:hover {
background: rgba(255, 75, 43, 0.9);
transform: translateY(-3px);
}
.pagination button.active {
background: linear-gradient(to right, #ff416c, #ff4b2b);
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(255, 75, 43, 0.4);
}
.pagination button:disabled {
opacity: 0.5;
cursor: not-allowed;
transform: none;
}
.pagination button i {
font-size: 14px;
}
@media (max-width: 768px) {
.video-grid {
grid-template-columns: 1fr;
}
h1 {
font-size: 2.2rem;
}
}
.wordpress-info {
text-align: center;
margin-top: 50px;
padding: 20px;
background: rgba(30, 30, 50, 0.5);
border-radius: 12px;
max-width: 800px;
margin: 50px auto 0;
}
.wordpress-info h3 {
color: #ff4b2b;
margin-bottom: 15px;
font-size: 1.5rem;
}
.code-block {
background: rgba(0, 0, 0, 0.3);
padding: 15px;
border-radius: 8px;
margin-top: 15px;
text-align: left;
font-family: monospace;
font-size: 0.9rem;
overflow-x: auto;
line-height: 1.5;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1><i class="fab fa-youtube"></i> YouTube Video Gallery</h1>
<p class="subtitle">Beautiful responsive gallery with pagination and hover effects. Perfect for WordPress sites. Easily switch between pages to view more content.</p>
</header>
<div class="video-grid" id="videoGrid">
<!-- Videos will be dynamically inserted here -->
</div>
<div class="pagination">
<button id="prevBtn" aria-label="Previous page"><i class="fas fa-chevron-left"></i></button>
<div class="page-numbers" id="pageNumbers"></div>
<button id="nextBtn" aria-label="Next page"><i class="fas fa-chevron-right"></i></button>
</div>
<div class="wordpress-info">
<h3>WordPress Integration</h3>
<p>To implement this on your WordPress site:</p>
<div class="code-block">
<?php<br>
// Add this code to your theme's functions.php or a custom plugin<br>
function youtube_video_gallery() {<br>
ob_start(); ?><br>
<div class="video-gallery-container"><br>
<!-- Paste the HTML structure here --><br>
</div><br>
<?php return ob_get_clean();<br>
}<br>
add_shortcode('youtube_gallery', 'youtube_video_gallery');<br>
?>
</div>
<p style="margin-top: 15px;">Then use the shortcode <strong>[youtube_gallery]</strong> in any post or page.</p>
</div>
</div>
<script>
// Sample video data (in a real WordPress site, this would come from your database)
const allVideos = [
{ id: 'dQw4w9WgXcQ', title: 'Never Gonna Give You Up', views: '1.2B', date: '3 years ago', duration: '3:32' },
{ id: '9bZkp7q19f0', title: 'Gangnam Style', views: '4.3B', date: '10 years ago', duration: '4:13' },
{ id: 'kJQP7kiw5Fk', title: 'Despacito', views: '7.9B', date: '6 years ago', duration: '4:41' },
{ id: 'OPf0YbXqDm0', title: 'Shape of You', views: '5.7B', date: '6 years ago', duration: '3:53' },
{ id: 'CevxZvSJLk8', title: 'See You Again', views: '5.3B', date: '8 years ago', duration: '3:49' },
{ id: 'RgKAFK5djSk', title: 'Waka Waka', views: '3.5B', date: '13 years ago', duration: '3:22' },
{ id: 'pRpeEdMmmQ0', title: 'Uptown Funk', views: '4.6B', date: '8 years ago', duration: '4:30' },
{ id: 'AJtDXIazrMo', title: 'Thinking Out Loud', views: '2.1B', date: '8 years ago', duration: '4:41' },
{ id: 'YQHsXMglC9A', title: 'Hello', views: '3.4B', date: '8 years ago', duration: '5:00' },
{ id: 'IcrbM1l_BoI', title: 'Sugar', views: '3.5B', date: '8 years ago', duration: '3:55' },
{ id: 'kOkQ4T5WO9E', title: 'Roar', views: '4.0B', date: '10 years ago', duration: '3:42' },
{ id: 'YqeW9_5kURI', title: 'Gentleman', views: '1.3B', date: '9 years ago', duration: '3:14' }
];
// Configuration
const videosPerPage = 6;
let currentPage = 1;
const totalPages = Math.ceil(allVideos.length / videosPerPage);
// DOM Elements
const videoGrid = document.getElementById('videoGrid');
const pageNumbers = document.getElementById('pageNumbers');
const prevBtn = document.getElementById('prevBtn');
const nextBtn = document.getElementById('nextBtn');
// Display videos for the current page
function displayVideos() {
videoGrid.innerHTML = '';
const startIndex = (currentPage - 1) * videosPerPage;
const endIndex = startIndex + videosPerPage;
const videosToShow = allVideos.slice(startIndex, endIndex);
videosToShow.forEach(video => {
const videoCard = document.createElement('div');
videoCard.className = 'video-card';
videoCard.innerHTML = `
<div class="video-thumb">
<img src="https://img.youtube.com/vi/${video.id}/maxresdefault.jpg" alt="${video.title}">
<div class="play-icon">
<i class="fas fa-play"></i>
</div>
<div class="video-duration">${video.duration}</div>
</div>
<div class="video-info">
<h3 class="video-title">${video.title}</h3>
<div class="video-meta">
<span>${video.views} views</span>
<span>${video.date}</span>
</div>
</div>
`;
videoGrid.appendChild(videoCard);
});
}
// Create pagination controls
function setupPagination() {
pageNumbers.innerHTML = '';
for (let i = 1; i <= totalPages; i++) {
const pageBtn = document.createElement('button');
pageBtn.textContent = i;
pageBtn.addEventListener('click', () => {
currentPage = i;
updatePagination();
displayVideos();
});
if (i === currentPage) {
pageBtn.classList.add('active');
}
pageNumbers.appendChild(pageBtn);
}
updatePagination();
}
// Update pagination button states
function updatePagination() {
prevBtn.disabled = currentPage === 1;
nextBtn.disabled = currentPage === totalPages;
// Update active class on page buttons
const pageButtons = pageNumbers.querySelectorAll('button');
pageButtons.forEach((btn, index) => {
if (index + 1 === currentPage) {
btn.classList.add('active');
} else {
btn.classList.remove('active');
}
});
}
// Event listeners for pagination
prevBtn.addEventListener('click', () => {
if (currentPage > 1) {
currentPage--;
updatePagination();
displayVideos();
}
});
nextBtn.addEventListener('click', () => {
if (currentPage < totalPages) {
currentPage++;
updatePagination();
displayVideos();
}
});
// Initialize the gallery
displayVideos();
setupPagination();
</script>
</body>
</html>
Features of this YouTube Video Gallery:
-
Responsive Grid Layout: Automatically adjusts to different screen sizes
-
Pagination System: Displays 6 videos per page with intuitive navigation
-
Hover Effects:
- Cards elevate and add shadow on hover
- Play button scales up and changes color
- Video thumbnail zooms slightly
- Title changes color on hover
-
Visual Design:
- Modern dark theme with gradient accents
- Clean card layout with video info
- YouTube-style elements (play button, duration label)
-
WordPress Integration:
- Includes code snippet for WordPress implementation
- Instructions for adding as a shortcode
- Responsive design works well with WordPress themes
To use this in WordPress:
- Add the provided PHP code to your theme's functions.php or a custom plugin
- Use the [youtube_gallery] shortcode in any post or page
- Customize the video data to match your content
The gallery is ready to use - just copy the entire HTML code into an HTML block in the WordPress editor, or implement it as a custom shortcode using the provided PHP snippet.