Created
September 3, 2018 21:34
-
-
Save olar94/f9d003d53cd61096a1732aa467c74b8e to your computer and use it in GitHub Desktop.
subcategory page template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Template Name: Category-Administrative | |
*/ | |
?> | |
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/style.css" type="text/css" media="screen" /> | |
<?php | |
// pagination | |
get_template_part('template-parts/paged'); | |
get_header(); | |
?> | |
<?php | |
$args = array( | |
'parent' => 18, //ID родительской категории | |
'hide_empty' => 0, | |
'exclude' => '', // ID рубрики, которую нужно исключить | |
'number' => '0', | |
'taxonomy' => 'category', // таксономия, для которой нужны изображения | |
'pad_counts' => true | |
); | |
$categories = get_categories($args); // получаем все категории в виде массива | |
$images_raw = get_option( 'taxonomy_image_plugin' ); // получаем все изображения в виде массива | |
$term_taxonomy_string = ''; | |
foreach ($categories as $category) { // перебираем массив полученных категорий | |
$term_taxonomy_id = $category->term_taxonomy_id; // узнаем ID категории | |
$term_taxonomy_name = $category->name; // узнаем имя категории | |
$term_taxonomy_image = wp_get_attachment_image( $images_raw[ $term_taxonomy_id ], 'full' ); // получаем прикрепленное изображение | |
$term_taxonomy_link = get_term_link((int)$term_taxonomy_id, 'category' ); // получаем ссылку на соответствующую рубрику | |
$term_taxonomy_string .= '<div class="category-card"> | |
<div class="thumbnail">'.$term_taxonomy_image.'</div> | |
<h3 class="category-title"><a class="link" href="'.$term_taxonomy_link.'">'.$term_taxonomy_name.'</a></h3> | |
</div>'; // формируем полученные данные и записываем в строку | |
} | |
echo $term_taxonomy_string; // выводим сформированную ранее строку - рубрики с изображениями | |
?> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment