@DemiurgeMaker
Я хороший

Почему Wordpress выводит обратный порядок категории и дочерняя первая?

На странице reklamavrostov.ru/port-57-2-2
Выводится путь Главная / Наружная реклама/Наши работы.
Должно выводится Главная / Наши работы/Наружная реклама. (т.к. Наши работы родительская категория Наружной рекламы).
Код шаблона страницы:
<?php get_header(); ?>

<div class="page-head">
  <div class="container">
      <div class="row">
      	<div class="col-md-12 col-sm-12 col-xs-12">
      	<p><a href="//reklamavrostov.ru">Главная</a> / <?php the_category('/'); ?></p>
      	
      	</div>
      </div>
  </div>
</div>
 
<section class="cnt">
  <div class="container">
      <div class="row portfoli">
      	<?php if (have_posts()) :  while (have_posts()) : the_post(); ?>
          <div class="col-md-12 col-sm-12 col-xs-12">
            <div class="post-cnt">
                <div class="post-cnt__text">
					<div class="col-md-6 col-md-push-6 col-sm-12 col-xs-12 contentpageportfolio">
						<h1><?php the_title(); ?></h1>		
						<h2>Закажите подобное решение</h2>
<a class="btn" data-toggle="modal" data-target="#myModal">Отправить</a>

					</div>
					<div class="col-md-6 col-md-pull-6 col-sm-12 col-xs-12">
						<a rel="[gallery]" href="<?php echo (get_post_meta($post->ID, 'img', true)); ?>">
							<img src="<?php echo (get_post_meta($post->ID, 'img', true)); ?>" alt="<?php the_title(); ?>" />
						</a>
							<?php the_content(); ?>
						<h2><strong>Еще наши работы</strong></h2>
<?php
function show_previous_posts_from_category ($the_post_id, $the_category_id = 0, $post_num) {
 
$num = 0;
global $wpdb;
 
$sql = "SELECT wposts.*
FROM $wpdb->posts wposts
LEFT JOIN $wpdb->term_relationships ON (wposts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
WHERE $wpdb->term_taxonomy.taxonomy = 'category'
AND $wpdb->term_taxonomy.term_id = '$the_category_id'
AND wposts.post_status = 'publish'
AND wposts.post_type = 'post'
AND wposts.ID < '$the_post_id'
ORDER BY wposts.ID DESC
LIMIT $post_num";
 
$result = $wpdb->get_results($sql, OBJECT);
global $post;
?>
<?php
foreach ($result as $post) {
setup_postdata($post);
?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a>
<?php
$num++;
$save_ids[] = $post->ID;
}
if ( $num < $post_num || !$result ) {
$need_more = $post_num-$num;
$save_ids[] = $the_post_id;
$save_ids = join (',', $save_ids);
$more_posts = get_posts("numberposts=$need_more&category=$the_category_id&exclude=$save_ids");
foreach ($more_posts as $post){
setup_postdata($post);
?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a>
<?php
}
}
?>
<?php } ?>
 
<?php
$the_cat = get_the_category();
$the_cat_id = $the_cat[0]->cat_ID;
show_previous_posts_from_category($post->ID, $the_cat_id, 3);
wp_reset_query();
?>
					</div>
					<!-- <div class="col-md-6 col-sm-12 col-xs-12 contentpageportfolio">
						<h1><?php the_title(); ?></h1>		
						<h2>Закажите подобное решение</h2>
<a class="btn" data-toggle="modal" data-target="#myModal">Отправить</a>

					</div> -->
                </div>
               
               <div class="article__social">

									<script type="text/javascript">(function() {
										if (window.pluso)if (typeof window.pluso.start == "function") return;
										if (window.ifpluso==undefined) { window.ifpluso = 1;
											var d = document, s = d.createElement('script'), g = 'getElementsByTagName';
											s.type = 'text/javascript'; s.charset='UTF-8'; s.async = true;
											s.src = ('https:' == window.location.protocol ? 'https' : 'http')  + '://share.pluso.ru/pluso-like.js';
											var h=d[g]('body')[0];
											h.appendChild(s);
										}})();</script>
									<div class="pluso" data-background="transparent" data-options="medium,round,line,horizontal,nocounter,theme=05" data-services="google,twitter,vkontakte,facebook,odnoklassniki"></div>
								</div>
            </div>
          </div>
        <?php endwhile; ?>
				<?php endif; ?>  
      </div>
  </div>
</section>

<?php get_footer(); ?>

Как поправить???
  • Вопрос задан
  • 69 просмотров
Пригласить эксперта
Ответы на вопрос 1
zorca
@zorca Куратор тега WordPress
the_category( '/', 'multiple');
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы