@zurabovi1

Сортировка записей в родительской категории Wordpress?

Здравствуйте, есть родительская категория "новости", в ней дочерние: новости о спорте, новости о звездах и т.д
Как сделать такую сортировку, чтобы после перехода на страницу род.категории "Новости", показывались записи сначала категории новости о спорте, потом новости о звездах, т.е. сортировка по категориями
  • Вопрос задан
  • 118 просмотров
Пригласить эксперта
Ответы на вопрос 1
@vaajnur
битриксоид
spoiler
<?php /* Template Name: CustomPageT1 */ ?>
<?php
/**
 * The template for displaying archive pages
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage Twenty_Seventeen
 * @since 1.0
 * @version 1.0
 */

get_header(); ?>

<div class="wrap">

	<?php if ( have_posts() ) : ?>
		<header class="page-header">
			<?php
				the_archive_title( '<h1 class="page-title">', '</h1>' );
				the_archive_description( '<div class="taxonomy-description">', '</div>' );
			?>
		</header><!-- .page-header -->
	<?php endif; ?>

	<div id="primary" class="content-area">
		<main id="main" class="site-main" role="main">

<?php 

$category_id = get_query_var( 'cat' ); // Get current catgory ID
$category = get_term( $category_id, 'category' ); // Fetch category term object

// get_categories(['']);

// Now, we check if the category has a parent
// If it has, we use that ID
// If it doesn't have a parent, it is a parent category itself and we use its own ID
$parent = $category->parent ? $category->parent : $category_id;

$args = array(
    'show_count' => false,
    'hide_empty' => false,
    'title_li' => '',
    'show_option_none' => '',
    'echo' => false
);

echo "parent: {$category->parent}";
// echo "category_id: $category_id";
// Show the children of parent category
if ( $category->parent ) {
    $args['child_of'] = $category->parent;
    $args['exclude'] = $category_id; // Don't display the current category in this list
}
else {
    // $args['child_of'] = $category_id;
}

// $args['show_option_all'] = 'Все';
$args['hide_empty'] = true;
// Get the category list
$categories_list = wp_list_categories( $args );

if ( $categories_list ) {
    ?>
    <div class="category-wrapper">
        <ul class="child-categories">
            <?php echo $categories_list; ?>
        </ul>
    </div>
    <?php
}

 ?>

		<?php
		if ( have_posts() ) : ?>
			<?php
			/* Start the Loop */
			while ( have_posts() ) : the_post();

				/*
				 * Include the Post-Format-specific template for the content.
				 * If you want to override this in a child theme, then include a file
				 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
				 */
				get_template_part( 'template-parts/post/content', get_post_format() );

			endwhile;

			the_posts_pagination( array(
				'prev_text' => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '<span class="screen-reader-text">' . __( 'Previous page', 'twentyseventeen' ) . '</span>',
				'next_text' => '<span class="screen-reader-text">' . __( 'Next page', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ),
				'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyseventeen' ) . ' </span>',
			) );




		else :

			get_template_part( 'template-parts/post/content', 'none' );


		endif; ?>

		</main><!-- #main -->
	</div><!-- #primary -->
	<?php get_sidebar(); ?>
</div><!-- .wrap -->

<?php get_footer();

Ответ написан
Ваш ответ на вопрос

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

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