/**
* Hizmetler 3×2 grid shortcode
* – Otomatik olarak “Hizmetlerimiz” sayfasının alt sayfalarını alır (parent = bulunduğun sayfa)
* – 3 sütun x 2 satır (en fazla 6 öğe)
* – Her kutu tıklanabilir ve featured image + başlık gösterir
* – Kullanım: [hizmetler_grid] (veya belirli parent için: [hizmetler_grid parent_id=”123″])
*/
function oz_hizmetler_grid_sc($atts){
global $post;
$atts = shortcode_atts( array(
‘parent_id’ => ( isset($post->ID) ? $post->ID : 0 ), // varsayılan: bulunduğu sayfa
‘count’ => 6,
‘cols’ => 3,
‘placeholder’ => ”, // opsiyonel: placeholder url
), $atts, ‘hizmetler_grid’ );
// Eğer parent_id boşsa 0 ile devam et (boş sonuç döner)
$parent_id = intval($atts[‘parent_id’]);
$args = array(
‘post_type’ => ‘page’,
‘posts_per_page’ => intval($atts[‘count’]),
‘post_parent’ => $parent_id,
‘orderby’ => ‘menu_order’,
‘order’ => ‘ASC’
);
$q = new WP_Query($args);
if ( ! $q->have_posts() ) {
return ‘
Henüz hizmet eklenmemiş veya bu sayfanın alt sayfası bulunmuyor.
‘;
}
// Başlangıç HTML
$html = ‘
$html .= ‘
$html .= ‘
while($q->have_posts()){
$q->the_post();
$link = get_permalink();
$title = get_the_title();
$post_id = get_the_ID();
// Featured image varsa kullan, yoksa placeholder
if ( has_post_thumbnail($post_id) ) {
$img = get_the_post_thumbnail( $post_id, ‘large’, array(‘alt’ => esc_attr($title)) );
} else {
// varsayılan placeholder: tema dizinindeki placeholder veya att’deki placeholder
if ( ! empty($atts[‘placeholder’]) ) {
$img = ‘‘;
} else {
$img = ‘
‘;
}
}
$html .= ‘‘;
$html .= ‘
‘;
$html .= ‘
‘. esc_html($title) .’
‘;
$html .= ‘‘;
}
wp_reset_postdata();
$html .= ‘
‘; // .oz-hizmetler-grid
$html .= ‘
‘; // .oz-hizmetler-wrap
// Inline CSS (hızlı çözüm). İstersen theme style.css’e taşı.
$html .= ‘
‘;
$html .= ‘
‘;
return $html;
}
add_shortcode(‘hizmetler_grid’,’oz_hizmetler_grid_sc’);
