if template pets in single.php

This commit is contained in:
2024-01-10 19:09:03 +03:00
parent a19eb845f0
commit 614d357ba7
6 changed files with 303 additions and 21 deletions

View File

@@ -1,8 +1,38 @@
<?php get_header();?>
<?php
// Указываем ID или slug основной рубрики
$pets_cat = false;
$pets_category_id_or_slug = 'pets';
// Получаем объект основной рубрики
$pets_category = get_term_by('slug', $pets_category_id_or_slug, 'category');
$post_categories = get_the_terms(get_the_ID(), 'category');
if ($post_categories && !is_wp_error($post_categories)) {
foreach ($post_categories as $post_category) {
if ($post_category->parent == $pets_category->term_id) {
$pets_cat = true;
break; // Мы уже нашли подходящую подрубрику, можно прервать цикл
}
}
} else {
$pets_cat = false;
}
echo "<!-- pets_cat: $pets_cat -->";
?>
<?php
if ( $pets_cat ){
get_header( 'pets' );
} else {
get_header();
}?>
<div id="content">
<?//while(have_posts()):?>
@@ -13,15 +43,27 @@
$category_id = $category[0]->term_id;
$category_link = get_category_link($category_id);
$post_id = get_the_ID();
?>
<ul id="nav_content">
<li><a href="<?=get_site_url()?>">Главная</li>
<li>-<li>
<li><a href="<?=$category_link?>"><?=$category['0']->name;?></a></li>
<li>-<li>
<li><?=mb_substr(get_the_title(), 0, 50);?>...</li>
</ul>
if ( $pets_cat ):?>
<ul id="nav_content">
<li><a href="<?=get_site_url()?>/category/pets">Питомцы</li>
<li>-<li>
<li><a href="<?=$category_link?>"><?=$category['0']->name;?></a></li>
<li>-<li>
<li><?=mb_substr(get_the_title(), 0, 50);?>...</li>
</ul>
<?else:?>
<ul id="nav_content">
<li><a href="<?=get_site_url()?>">Главная</li>
<li>-<li>
<li><a href="<?=$category_link?>"><?=$category['0']->name;?></a></li>
<li>-<li>
<li><?=mb_substr(get_the_title(), 0, 50);?>...</li>
</ul>
<?endif?>
<div class="post_info">
<div class="post_info_sub">
@@ -117,7 +159,10 @@
<?php
if ( $pets_cat ){
get_footer( 'pets' );
} else {
get_footer();
}?>
<?php get_footer();?>