/*
* بخش اول: طراحی صفحه تکی پزشک (Single Doctor Page)
* این بخش محتوای صفحه داخلی دکتر را تغییر می‌دهد.
*/
function custom_doctor_single_layout( $content ) {

// فقط اگر در صفحه تکی پزشک هستیم اجرا شود
if ( is_singular(‘doctors’) && in_the_loop() && is_main_query() ) {

$post_id = get_the_ID();

// 1. گرفتن عکس
$image = get_the_post_thumbnail( $post_id, ‘medium’, array( ‘class’ => ‘doctor-profile-img’ ) );
if ( ! $image ) {
$image = ‘‘;
}

// 2. گرفتن نام پزشک
$name = get_the_title();

// 3. گرفتن تخصص (ACF)
$specialty = ”;
if ( function_exists(‘get_field’) ) {
$specialty_value = get_field(‘doctor_specialty’, $post_id);
if( $specialty_value ) {
$specialty = ‘

‘ . $specialty_value . ‘

‘;
}
}

// ساختار HTML جدید برای صفحه تکی
$custom_layout = ‘

‘ . $image . ‘

‘ . $name . ‘

‘ . $specialty . ‘

‘ . $content . ‘

‘;

return $custom_layout;
}

// اگر صفحه پزشک نبود، محتوا را دست نخورده برگردان
return $content;
}
add_filter( ‘the_content’, ‘custom_doctor_single_layout’ );

/*
* بخش دوم: نمایش تخصص زیر اسم در صفحه آرشیو/لیست (Archive)
* این بخش به جای محتوا، عنوان (Title) را فیلتر می‌کند.
*/
function show_specialty_under_title_archive( $title, $id ) {

// شرط‌ها: در ادمین نباشیم، در حلقه اصلی باشیم و صفحه آرشیو پزشکان باشد
if ( !is_admin() && in_the_loop() && is_post_type_archive(‘doctors’) ) {

if ( function_exists(‘get_field’) ) {
$specialty = get_field(‘doctor_specialty’, $id);

if ( $specialty ) {
// اضافه کردن تخصص زیر عنوان
$title .= ‘

‘ . $specialty . ‘

‘;
}
}
}

return $title;
}
add_filter( ‘the_title’, ‘show_specialty_under_title_archive’, 10, 2 );

Comments are disabled.