add block partname in pets

This commit is contained in:
2024-01-15 20:18:49 +03:00
parent bdaa643c7d
commit 0acaed405a

View File

@@ -13,14 +13,18 @@
foreach ($post_categories as $post_category) { foreach ($post_categories as $post_category) {
if ($post_category->parent == $pets_category->term_id) { if ($post_category->parent == $pets_category->term_id) {
$pets_cat = true; $pets_cat = true;
break; // Мы уже нашли подходящую подрубрику, можно прервать цикл $category_id = $post_category->term_id;
$category_name = $post_category->name;
$category_link = get_category_link($category_id);
break;
} }
} }
} else { } else {
$pets_cat = false; $pets_cat = false;
} }
echo "<!-- pets_cat: $pets_cat -->"; $post_id = get_the_ID();
?> ?>
@@ -39,25 +43,27 @@ if ( $pets_cat ){
<?the_post();?> <?the_post();?>
<?php $category = get_the_category(); <?php
$category_id = $category[0]->term_id;
$category_link = get_category_link($category_id);
$post_id = get_the_ID();
if ( $pets_cat ):?> if ( $pets_cat ):?>
<?echo "<!-- pets: $category_name-->"?>
<ul id="nav_content"> <ul id="nav_content">
<li><a href="<?=get_site_url()?>/category/pets">Питомцы</li> <li><a href="<?=get_site_url()?>/category/pets">Питомцы</li>
<li>-<li> <li>-<li>
<li><a href="<?=$category_link?>"><?=$category['0']->name;?></a></li> <li><a href="<?=$category_link?>"><?echo $category_name;?></a></li>
<li>-<li> <li>-<li>
<li><?=mb_substr(get_the_title(), 0, 50);?>...</li> <li><?=mb_substr(get_the_title(), 0, 50);?>...</li>
</ul> </ul>
<?else:?> <?else:
$category = get_the_category();
$category_id = $category[0]->term_id;
$category_name = $category['0']->name;
$category_link = get_category_link($category_id);?>
<ul id="nav_content"> <ul id="nav_content">
<li><a href="<?=get_site_url()?>">Главная</li> <li><a href="<?=get_site_url()?>">Главная</li>
<li>-<li> <li>-<li>
<li><a href="<?=$category_link?>"><?=$category['0']->name;?></a></li> <li><a href="<?=$category_link?>"><?=$category_name;?></a></li>
<li>-<li> <li>-<li>
<li><?=mb_substr(get_the_title(), 0, 50);?>...</li> <li><?=mb_substr(get_the_title(), 0, 50);?>...</li>
</ul> </ul>
@@ -67,7 +73,7 @@ if ( $pets_cat ){
<div class="post_info"> <div class="post_info">
<div class="post_info_sub"> <div class="post_info_sub">
<span class="post_link_category"><a href="<?=$category_link?>"><?=$category['0']->name;?></a></span>, <nobr><?php the_time('j F Y, G:i');?></nobr> <span class="post_link_category"><a href="<?=$category_link?>"><?=$category_name;?></a></span>, <nobr><?php the_time('j F Y, G:i');?></nobr>
</div> </div>
<div class="post_info_sub post_info_social"> <div class="post_info_sub post_info_social">
<?php include get_template_directory().'/blocks/social-share.php';?> <?php include get_template_directory().'/blocks/social-share.php';?>