Ayto einai dokimastiko arthro

 

[pdf-embedder url=”https://actions.goldenhost.gr/wp-content/uploads/2025/03/dummy.pdf”]

 

// Shortcode: district_hierarchy
function district_hierarchy_shortcode($atts) {
$atts = shortcode_atts([
‘taxonomy’ => ‘category’, // default αν δεν δώσεις
‘post_id’ => get_the_ID(),
], $atts, ‘district_hierarchy’);

$post_id = intval($atts[‘post_id’]);
$taxonomy = sanitize_text_field($atts[‘taxonomy’]);

$terms = get_the_terms($post_id, $taxonomy);
if (!$terms || is_wp_error($terms)) return ”;

// Ομαδοποίηση ανά parent
$by_parent = [];
foreach ($terms as $term) {
$by_parent[$term->parent][] = $term;
}

if (empty($by_parent[0])) return ”;

$html = ”;
foreach ($by_parent[0] as $parent) {
$html .= ‘<div class=”term-block”>’;
$html .= ‘<h3 class=”parent-term”><a href=”‘ . esc_url(get_term_link($parent)) . ‘”>’ . esc_html($parent->name) . ‘</a></h3>’;

if (!empty($by_parent[$parent->term_id])) {
$html .= ‘<ul>’;
foreach ($by_parent[$parent->term_id] as $child) {
$html .= ‘<li><a href=”‘ . esc_url(get_term_link($child)) . ‘”>’ . esc_html($child->name) . ‘</a></li>’;
}
$html .= ‘</ul>’;
}

$html .= ‘</div>’;
}

return $html;
}
add_shortcode(‘district_hierarchy’, ‘district_hierarchy_shortcode’);

https://actions.goldenhost.gr/wp-content/uploads/2025/03/dummy.pdf