<?php
// Exit if accessed directly
if (!defined('ABSPATH')) exit;
/**
*Full Content Template
Template Name: Profolio Details
*@file single-portfolios.php
*@package ahm
*@author Md Rabiul Islam Robin
*@copyright 2025
*@license
*@version 1.0
*@filesource ahm/single-portfolios.php
*@since ahm 1.0
*/
get_header();
?>
<?php
if (have_posts()):
while (have_posts()): the_post();
?>
<!-----------------------------------------------
Protfolio Details Header
------------------------------------------------->
<div
class="breadcrumb-wrapper fix"
style="background-image: url(<?php echo get_template_directory_uri(); ?>/image/contact\ bg.jpg)"
id="contact-page">
<div class="star-shape-c float-bob-x">
<img src="image/star.png" alt="" />
</div>
<div class="container">
<div class="row">
<div class="page-heading">
<h2>
<?php
$terms = wp_get_post_terms(get_the_ID(), 'protfolio-categories'); // Toolset taxonomy slug
if (!empty($terms) && !is_wp_error($terms)) {
echo $terms[0]->name;
}
?>
</h2>
<ul class="breadcrumb-list">
<li><a href="<?php echo home_url(); ?>">Home</a></li>
<li><i class="fa-solid fa-angle-right"></i></li>
<li>
<?php
$terms = wp_get_post_terms(get_the_ID(), 'protfolio-categories'); // Toolset taxonomy slug
if (!empty($terms) && !is_wp_error($terms)) {
// শুধু প্রথম selected category দেখাবে
echo $terms[0]->name;
}
?>
</li>
</ul>
</div>
</div>
</div>
</div>
<!-----------------------------------------------
Protfolio Details Section
------------------------------------------------->
<div class="protfolio-section fix">
<div class="container">
<div class="row row-portfolio">
<div class="col-lg-8 order-lg-2">
<div class="pro-details-wrapper">
<?php
// সব child posts নিয়ে আসি
$child_posts = toolset_get_related_posts(
$post->ID,
'portfolio-d-project',
array(
'query_by_role' => 'parent',
'return' => 'post_object'
)
);
// Pagination setup
$posts_per_page = 5;
$total_posts = count($child_posts);
$total_pages = ceil($total_posts / $posts_per_page);
// URL parameter থেকে বর্তমান পেজ বের করি (যেমন ?pg=2)
$paged = isset($_GET['pg']) ? intval($_GET['pg']) : 1;
if ($paged < 1) $paged = 1;
if ($paged > $total_pages) $paged = $total_pages;
// কোন item থেকে শুরু হবে
$offset = ($paged - 1) * $posts_per_page;
// array_slice দিয়ে pagination করি
$paged_posts = array_slice($child_posts, $offset, $posts_per_page);
if ($paged_posts) {
foreach ($paged_posts as $item) {
?>
<div class="pro-items">
<div class="pro-thumb">
<img src="<?php echo get_post_meta($item->ID, 'wpcf-portfolio-d-p-image', true); ?>" alt="">
</div>
<div class="pro-content">
<div class="pro-d-c d-flex">
<div class="pro-c">
<?php
$terms = wp_get_post_terms(get_the_ID(), 'protfolio-categories'); // Toolset taxonomy slug
if (!empty($terms) && !is_wp_error($terms)) {
echo $terms[0]->name;
}
?>
</div>
<div class="pro-date">
<div class="pro-dot"></div>
<div class="pro-date-c"><?php echo get_post_meta($item->ID, 'wpcf-portfolio-d-p-date', true); ?></div>
</div>
</div>
<div class="pro-heading">
<h3 class="limit-text"><?php echo get_post_meta($item->ID, 'wpcf-portfolio-d-title', true); ?></h3>
<p><?php echo get_post_meta($item->ID, 'wpcf-protfolio-d-category', true); ?></p>
<p><?php echo get_post_meta($item->ID, 'wpcf-position-type', true); ?></p>
</div>
<div class="pro-btn">
<div class="pro-icon"><a href="#"><i class="fa-solid fa-arrow-right"></i></a></div>
<a href="<?php echo get_post_meta($item->ID, 'wpcf-portfolio-details-link', true); ?>" class="pro-b-content" target="_blank">Read More</a>
</div>
</div>
</div>
<?php
}
} else {
echo '<p>No items found.</p>';
}
?>
<!-- Pagination -->
<!-- Pagination -->
<?php if ($total_pages > 1): ?>
<div class="pro-pagination">
<ul>
<?php
// কতগুলো পেজ একসাথে দেখাবে
$visible_pages = 3;
// বর্তমান group এর শুরু এবং শেষ নির্ণয়
$start_page = max(1, $paged - floor($visible_pages / 2));
$end_page = $start_page + $visible_pages - 1;
if ($end_page > $total_pages) {
$end_page = $total_pages;
$start_page = max(1, $end_page - $visible_pages + 1);
}
?>
<!-- Prev button -->
<?php if ($paged > 1): ?>
<li><a href="?pg=<?php echo $paged - 1; ?>"><i class="fa-solid fa-arrow-left"></i></a></li>
<?php endif; ?>
<!-- Page numbers -->
<?php for ($i = $start_page; $i <= $end_page; $i++): ?>
<li class="<?php echo ($i == $paged) ? 'active' : ''; ?>">
<a href="?pg=<?php echo $i; ?>"><?php echo $i; ?></a>
</li>
<?php endfor; ?>
<!-- Next button -->
<?php if ($paged < $total_pages): ?>
<li><a href="?pg=<?php echo $paged + 1; ?>"><i class="fa-solid fa-arrow-right"></i></a></li>
<?php endif; ?>
</ul>
</div>
<?php endif; ?>
</div>
</div>
<div class="col-lg-4 order-lg-1">
<div class="pro-side-bar">
<div class="single-sidebar">
<div class="categories-heading">
<h3>Categories</h3>
</div>
<div class="categories-list">
<ul>
<?php
// Fetch all portfolio categories
$terms = get_terms(array(
'taxonomy' => 'protfolio-categories',
'hide_empty' => false,
'orderby' => 'term_order', // Plugin er order maintain korbe
'order' => 'ASC'
));
if ($terms && !is_wp_error($terms)) :
foreach ($terms as $term) :
// Get all posts in this category (IDs only)
$posts_in_category = get_posts(array(
'post_type' => 'portfolios',
'tax_query' => array(
array(
'taxonomy' => 'protfolio-categories',
'field' => 'term_id',
'terms' => $term->term_id,
)
),
'posts_per_page' => -1,
'fields' => 'ids', // Only IDs
));
$total_items = 0;
$post_link = '#'; // Default link if no posts
if (!empty($posts_in_category)) {
// Count all child posts for each post
foreach ($posts_in_category as $post_id) {
$child_posts = toolset_get_related_posts(
$post_id,
'portfolio-d-project', // Relationship slug
array(
'query_by_role' => 'parent',
'return' => 'post_object'
)
);
$total_items += !empty($child_posts) ? count($child_posts) : 0;
}
// Get link of the first post in this category
$first_post_id = $posts_in_category[0];
$post_link = get_permalink($first_post_id);
}
?>
<li>
<a href="<?php echo esc_url($post_link); ?>">
<?php echo esc_html($term->name); ?>
<span>(<?php echo $total_items; ?>)</span>
</a>
</li>
<?php
endforeach;
endif;
?>
</ul>
</div>
</div>
<div class="single-sidebar side-pb-contact" style="background-image: url(<?php echo get_template_directory_uri(); ?>/image/publication/pb-banner.png);">
<div class="info-widget">
<div class="logo">
<img src="image/theme logo.png" alt="">
</div>
<div class="content">
<h3>Don't Hesitate to Contact Me</h3>
<h5>+880 17110-54215</h5>
</div>
<a href="contact.html" class="info-btn">Get In Touch <i class="fa-solid fa-arrow-right"></i></a>
</div>
</div>
<div class="single-sidebar">
<div class="categories-heading">
<h3>Recent Project</h3>
</div>
<div class="recent">
<div class="rec-wrapper">
<?php
// বর্তমান portfolio post ID
$parent_id = get_the_ID();
// current portfolio post-এর child posts fetch করা
$child_posts = toolset_get_related_posts(
$parent_id,
'portfolio-d-project', // child post type / relationship slug
array(
'query_by_role' => 'parent',
'return' => 'post_object'
)
);
// check করি child post আছে কি না
if (!empty($child_posts)) :
// array_reverse() দিয়ে last post গুলো প্রথমে
$child_posts = array_reverse($child_posts);
// সর্বশেষ 3টি child post দেখাই
$recent_child_posts = array_slice($child_posts, 0, 3);
foreach ($recent_child_posts as $item) :
?>
<div class="recent-items">
<a href="<?php echo get_post_meta($item->ID, 'wpcf-portfolio-details-link', true); ?>" class="rec-items" target="_blank">
<img src="<?php echo get_post_meta($item->ID, 'wpcf-portfolio-d-p-image', true); ?>" alt="">
<div class="rec-content">
<h4 style="limit-text2">
<?php echo get_post_meta($item->ID, 'wpcf-portfolio-d-title', true); ?>
</h4>
<p><?php echo get_post_meta($item->ID, 'wpcf-portfolio-d-p-date', true); ?></p>
</div>
</a>
</div>
<?php
endforeach;
else :
echo '<p>No Project Found.</p>';
endif;
?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
endwhile;
endif;
?>
<?php get_footer(); ?>