Skip to content

Instantly share code, notes, and snippets.

@eto4detak
Last active February 13, 2018 11:08
Show Gist options
  • Save eto4detak/c3a977327e10c029e52fd38d600fc6e3 to your computer and use it in GitHub Desktop.
Save eto4detak/c3a977327e10c029e52fd38d600fc6e3 to your computer and use it in GitHub Desktop.
wp php taxonomy.php
<?php get_header(); ?>
<div class="wrapper">
<div class="middle">
<div class="breadcrumbs">
<?php if (function_exists('yoast_breadcrumb')) {
yoast_breadcrumb('<p id="breadcrumbs">', '</p>');
} ?>
</div><!-- .breadcrumbs-->
<section itemscope itemtype="http://schema.org/Blog" class="content">content
<div class="category-title">
<?php
$taxonomy_access = array('nemtsy', 'auto', 'chd2');
$taxonomy_access_id = array('11', '12');
$queried_object = get_queried_object();
$term_id = $queried_object->term_id;
?>
<h1 itemprop="headline"><?php single_cat_title(); ?></h1>
<div itemprop="description" class="category-description"><?php echo html_entity_decode(get_term_meta( $term_id, 'down_opis', true )); ?>
</div>
<?php
function printResource($term_id, $in_top_meta_value) {
$args = array(
'posts_per_page' => -1,
'post_type' => 'resource',
'meta_query' => array(
array(
'key' => 'in_top_meta',
'value' => $in_top_meta_value,
'compare' => '=='
)
),
'tax_query' => array(
array(
'taxonomy' => 'collection',
'field' => 'term_id',
'terms' => $term_id,
'include_children' => false,
),
),
'meta_key' => 'ec_stars_rating_ava',
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
$query = new WP_Query( $args ); ?>
<?php if ($query->have_posts()): ?>
<?php while ($query->have_posts()) : $query->the_post(); ?>
<?php $fav_url = get_post_meta(get_the_ID(), 'fav_url', true); ?>
<?php $ancor_url = get_post_meta(get_the_ID(), 'ancor_url', true); ?>
<?php if (!$ancor_url) {$ancor_url = "Перейти на сайт";} ?>
<div class="blueTable">
<div class="cname"><?php if ($fav_url) { ?><img alt="<?php the_title(); ?>" style="margin-right: 10px;vertical-align: baseline;" width="15" height="15" src="<?php echo $fav_url; ?>" /><?php } ?><a class="dlink" href="<?php echo get_the_permalink(); ?>" target="_blank" rel="noopener"><strong><?php the_title(); ?></strong></a></div>
<div class="crating"><?php if(function_exists('ec_stars_rating')) {ec_stars_rating();} ?></div>
<div class="pereiti">
<div class="buttonlink">
<?php if ($in_top_meta_value == 'yes') { echo 'Перейти на '; }; ?>
<span class="link" data-link="<?php echo get_post_meta(get_the_ID(), 'res_url', true); ?>"><?php echo $ancor_url; ?></span>
</div>
</div>
</div>
<?php endwhile; endif; ?>
<?php wp_reset_query();
}
?>
<!-- 1 -->
<?php if(in_array($queried_object->slug, $taxonomy_access) || in_array($term_id, $taxonomy_access_id)) : ?>
<div class="categories">
<div class="ads">
<a href="https://www.yandex.ru/"><img src="http://placehold.it/300x250"></a>
</div>
<?php
$taxonomy_name = 'collection';
$term_children = get_term_children( $term_id, $taxonomy_name );
if ($term_children) {
foreach ( $term_children as $child ) :
$term = get_term_by( 'id', $child, $taxonomy_name );
if($term->parent === $term_id) :
?><li class="item-category">
<?php
if(!$url = get_term_meta( $term->term_id, 'collection_thumb', true )) $url = 'http://placehold.it/300x250';
?>
<a href="<?php echo get_term_link( $child, $taxonomy_name ) ?>">
<img class="img-category" title="" alt="" width="300" height="200" src="<?php echo $url ?>">
</a>
<h3>
<a href="<?php echo get_term_link( $child, $taxonomy_name ) ?>"><?php echo $term->name?></a>
</h3>
</li>
<?php endif; ?>
<?php endforeach; ?>
<?php wp_reset_query();
}
?>
<div class="ads">
<a href="https://www.yandex.ru/"><img src="http://placehold.it/300x250"></a>
</div>
</div>
<?php else : ?>
<?php
/*========================================================
* 2
========================================================*/
$queried_object = get_queried_object();
$term_id = $queried_object->term_id;
$args = array(
'posts_per_page' => -1,
'meta_key' => 'in_top_meta',
'meta_value' => 'yes',
'post_type' => 'resource',
'tax_query' => array(
array(
'taxonomy' => 'collection',
'field' => 'term_id',
'terms' => $term_id,
'include_children' => false,
)
),
);
$query = new WP_Query( $args ); ?>
<?php if ($query->have_posts()):?>
<?php while ($query->have_posts()) : $query->the_post(); ?>
<?php $fav_url = get_post_meta(get_the_ID(), 'fav_url', true); ?>
<?php $ancor_url = get_post_meta(get_the_ID(), 'ancor_url', true); ?>
<?php if (!$ancor_url) {$ancor_url = "Перейти на сайт";} ?>
<div class="blueTable">
<div class="cname">
<?php if ($fav_url) { ?><img alt="<?php the_title(); ?>" style="margin-right: 10px;vertical-align: baseline;" width="15" height="15" src="<?php echo $fav_url; ?>" /><?php } ?>
<a class="dlink" href="<?php echo get_the_permalink(); ?>" target="_blank" rel="noopener"><strong><?php the_title(); ?></strong></a>
</div>
<div class="crating">
<?php if(function_exists('ec_stars_rating')) {ec_stars_rating();} ?>
</div>
<div class="pereiti">
<div class="buttonlink">Перейти на <span class="link" data-link="<?php echo get_post_meta($post->ID, 'res_url', true); ?>"><?php echo $ancor_url; ?></span></div>
</div>
</div>
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
<?php
$args = array(
'posts_per_page' => -1,
'post_type' => 'resource',
'meta_query' => array(
array(
'key' => 'in_top_meta',
'value' => 'no',
'compare' => '=='
)
),
'tax_query' => array(
array(
'taxonomy' => 'collection',
'field' => 'term_id',
'terms' => $term_id,
'include_children' => false,
),
),
'meta_key' => 'ec_stars_rating_ava',
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
$query = new WP_Query( $args ); ?>
<?php if ($query->have_posts()): ?>
<?php while ($query->have_posts()) : $query->the_post(); ?>
<?php $fav_url = get_post_meta(get_the_ID(), 'fav_url', true); ?>
<?php $ancor_url = get_post_meta(get_the_ID(), 'ancor_url', true); ?>
<?php if (!$ancor_url) {$ancor_url = "Перейти на сайт";} ?>
<div class="blueTable">
<div class="cname">
<?php if ($fav_url) { ?><img alt="<?php the_title(); ?>" style="margin-right: 10px;vertical-align: baseline;" width="15" height="15" src="<?php echo $fav_url; ?>" /><?php } ?>
<a class="dlink" href="<?php echo get_the_permalink(); ?>" target="_blank" rel="noopener"><strong><?php the_title(); ?></strong></a>
</div>
<div class="crating">
<?php if(function_exists('ec_stars_rating')) {ec_stars_rating();} ?>
</div>
<div class="pereiti">
<div class="buttonlink">
<span class="link" data-link="<?php echo get_post_meta($post->ID, 'res_url', true); ?>"><?php echo $ancor_url; ?></span>
</div>
</div>
</div>
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
<?php
$taxonomy_name = 'collection';
$term_children = get_term_children( $term_id, $taxonomy_name );
$term_childrens_ids = array();
if ($term_children) {
foreach ( $term_children as $child ) {
$term = get_term_by( 'id', $child, $taxonomy_name );
if( !in_array($term->term_id, $term_childrens_ids) ) {
echo '<h2 class="taxonom"><a href="' . get_term_link( $child, $taxonomy_name ) . '">'. $term->name .'</a></h2>';
echo '<div class="ads"><a href="https://www.yandex.ru/"><img src="http://placehold.it/728x90"></a></div>';
$term_children_children = get_term_children( $child, $taxonomy_name );
if ($term_children_children) {
// выводим ресурсы
printResource($term->term_id, 'yes');
printResource($term->term_id, 'no');
foreach ( $term_children_children as $child_child ) {
$term_child = get_term_by( 'id', $child_child, $taxonomy_name );
echo '<h3 class="taxonom"><a href="' . get_term_link( $child_child, $taxonomy_name ) . '">'. $term_child->name .'</a></h3>';
echo '<div class="ads"><a href="https://www.yandex.ru/"><img src="http://placehold.it/728x90"></a></div>';
array_push($term_childrens_ids, $term_child->term_id);
// выводим ресурсы
printResource($child_child, 'yes');
printResource($child_child, 'no');
}
} else {
// выводим ресурсы
printResource($term->term_id, 'yes');
printResource($term->term_id, 'no');
}
}
}
}
?>
<?php endif; ?>
</section><!-- /content -->
<br>
<div itemprop="description" class="category-description"><?php echo category_description(); ?></div>
<ul class="qwerty">
<?php $term_id;
$mass = array('collection_q','collection_w','collection_e','collection_r','collection_t',);
foreach ($mass as $value ) {
if(($url = get_term_meta( $term_id, $value, true )) && ($name = get_term_meta( $term_id, $value . '_2', true ))) :
?><li><a href="<?php echo $url; ?>"><?php echo $name ;?></a></li>
<?php endif;
}
?>
</ul>
<!--noindex-->
<div class="post-share">
<span class="views">
<span class="icon icon-eye"></span><?php
$queried_object = get_queried_object();
$term_id = $queried_object->term_id;
$collection_views = get_term_meta( $term_id, 'collection_views', true );
$collection_views++;
update_term_meta( $term_id, 'collection_views', $collection_views );
echo $collection_views;?>
</span>
<span class="share1">Добавь к себе на стену:</span>
<span class="ya-share2" data-services="collections,facebook,odnoklassniki,vkontakte,gplus,twitter,pinterest,telegram,moimir,pocket,surfingbird,blogger,linkedin,lj,viber,whatsapp,skype" data-image="https://101poisk.ru/banner/pinterest.png" data-limit="7" style="display: inline-block;"></span>
</div>
<br>
<div class="related-posts-title">Вам так же может быть интересно</div>
<!--/noindex-->
<br>
<div class="related-posts">
<?php the_related_posts(); ?>
</div>
<br>
</div><!-- .middle-->
<?php get_template_part( 'header', 'nav' ); ?>
<?php get_sidebar(); ?>
</div><!-- /wrapper -->
<?php get_footer();
/*========================================================
* Список таксономии collection с дочерними
========================================================*/
/* $args = array(
'taxonomy' => 'collection',
'hide_empty' => false,
);
$terms = get_terms( $args );
if ( !empty( $terms ) && !is_wp_error( $terms ) ) {
$count = count($terms);
$term_list .= '<div id="jquery-accordion-menu" class="jquery-accordion-menu green">';
$term_list .= '<ul id="demo-list">';
foreach ($terms as $term) {
if($term->parent === 0){
$term_list .= '<li class=""><a href="' . get_term_link( $term->term_id ) . '"> ' . $term->name . '</a>';
$term_children = get_term_children( $term->term_id, 'collection' );
if($term_children) {
$term_list .= '<ul class="submenu">';
foreach ($term_children as $item) {
foreach ($terms as $tt) {
if($tt->term_id === $item)
$term_list .= '<li class=""><a href="' . get_term_link( $tt->term_id ) . '"> ' . $tt->name . '</a></li>';
}
}
$term_list .= '</ul>';
}
$term_list .= '</li>';
}
}
$term_list .= '</ul>';
$term_list .= '</div>';
}*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment