Baurzhan сказал(а)
Не работает вывод меток товаров
что значит "не работает"? вывод меток в функционале дополнения не заявлен. На этом сайте кастомный вывод меток, если хочется такой же, то размещайте в файле функций своей темы код:
function rcl_the_product_category_tags() { global $wp_query; if ( $wp_query->is_tax( array( 'prodcat' ) ) ) { global $wpdb; $term = get_term_by( 'slug', $wp_query->query_vars['prodcat'], 'prodcat' ); $tags = $wpdb->get_results( "SELECT DISTINCT " . "terms2.term_id as tag_id, " . "terms2.name as tag_name, " . "terms2.slug as tag_slug, " . "t2.count as posts_count " //. "null as tag_link " . "FROM " . "$wpdb->posts as p1 " . "LEFT JOIN $wpdb->term_relationships as r1 ON p1.ID = r1.object_ID " . "LEFT JOIN $wpdb->term_taxonomy as t1 ON r1.term_taxonomy_id = t1.term_taxonomy_id " . "LEFT JOIN $wpdb->terms as terms1 ON t1.term_id = terms1.term_id, " . "$wpdb->posts as p2 " . "LEFT JOIN $wpdb->term_relationships as r2 ON p2.ID = r2.object_ID " . "LEFT JOIN $wpdb->term_taxonomy as t2 ON r2.term_taxonomy_id = t2.term_taxonomy_id " . "LEFT JOIN $wpdb->terms as terms2 ON t2.term_id = terms2.term_id " . "WHERE " . "t1.taxonomy = 'prodcat' AND p1.post_status = 'publish' AND terms1.slug IN ('" . $wp_query->query_vars['prodcat'] . "') AND " . "t2.taxonomy = 'product_tag' AND p2.post_status = 'publish' " . "AND p1.ID = p2.ID " . "AND t2.count > '9'" . "ORDER by posts_count DESC" ); if ( ! $tags ) return false; $content = '<div class="popular-category-tags">'; $content .= 'Популярные метки: '; $tagsArray = array(); foreach ( $tags as $tag ) { $tagsArray[] = '<a href="' . get_term_link( ( int ) $term->term_id, 'prodcat' ) . '?product-tag=' . $tag->tag_slug . '" ' . (isset( $_GET['product-tag'] ) && $_GET['product-tag'] == $tag->tag_slug ? 'class="active-tag"' : '') . '>' . $tag->tag_name . '</a>'; } $content .= implode( ', ', $tagsArray ); $content .= '</div>'; echo $content; } }
а затем в шаблоне архива, в нужном месте, разместите код
<?php rcl_the_product_category_tags(); ?>
если вы не знаете, что такое файл функций темы или шаблон архива, то погуглите или найдите специалиста, это общие вопросы по WP, а предложенный код является кастомизацией, в рамки поддержки он не входит.
в файле функций также надо будет разместить еще и это
add_action( 'pre_get_posts', 'pre_get_groups_category_filter' ); function pre_get_groups_category_filter( $query ) { if ( ! is_admin() && $query->is_main_query() ) { if ( $query->is_tax( array( 'prodcat' ) ) && isset( $_GET['product-tag'] ) ) { $query->set( 'tax_query', array( array( 'taxonomy' => 'product_tag', 'field' => 'slug', 'terms' => $_GET['product-tag'] ), array( 'taxonomy' => 'prodcat', 'field' => 'slug', 'terms' => $query->query_vars['prodcat'] ) ) ); } } }
Извиняюсь, может не так выразился, думал можно было вывести метки как подменю и там будут товары по меткам/категории
а затем в шаблоне архива, в нужном месте, разместите код
Не пойму, куда вставить этот код
<?php rcl_the_product_category_tags(); ?>
Эта дочерняя тема наследует шаблоны из родительской — Hueman.
Таблица стилей
(style.css)
Функции темы
(functions.php)
archive-products.php
Архивы
(archive.php)
Шаблон автора
(author.php)
taxonomy-groups.php
taxonomy-prodcat.php
taxonomy-product_tag.php
добавил коды функции, не знаю куда вставить код <?php rcl_the_product_category_tags(); ?>
Вот так выглядит список товаров
Если нажать на категорию или метку, то товаров нет
Просто хочу сделать категории с метками товаров, как реализовано у вас на сайте, потому что товаров будет много
Пробовал по разному
Hueman Child WP-Recall: Функции темы (functions.php)
<?php function hueman_child_theme_setup() { load_child_theme_textdomain( 'hueman', get_stylesheet_directory() . '/languages' ); } add_action( 'after_setup_theme', 'hueman_child_theme_setup' ); new Hueman_Child_Customizer(); class Hueman_Child_Customizer{ public function __construct() { add_action ('admin_menu', array(&$this, 'customizer_admin')); add_action( 'customize_register', array(&$this, 'customize_manager_demo' )); } /** * Add the Customize link to the admin menu * @return void */ public function customizer_admin() { add_theme_page( 'Настройки WP-Recall', 'Настройки WP-Recall', 'edit_theme_options', 'customize.php' ); } /** * Customizer manager demo * @param WP_Customizer_Manager $wp_manager * @return void */ public function customize_manager_demo( $wp_manager ) { $this->demo_section( $wp_manager ); } public function demo_section( $wp_manager ) { $wp_manager->add_section( 'customiser_child_theme_section', array( 'title' => 'Настройки WP-Recall', 'priority' => 35, ) ); // Select control $wp_manager->add_setting( 'output_products_list', array( 'default' => '1', ) ); $wp_manager->add_control( 'output_products_list', array( 'label' => 'Порядок вывода товаров на архивных страницах', 'section' => 'customiser_child_theme_section', 'type' => 'select', 'choices' => array('list'=>"Списком", 'slab'=>"Плиткой"), 'priority' => 4 ) ); } } if(function_exists('rcl_tab')) add_action('init','rcl_add_tab_salelinks'); function rcl_add_tab_salelinks(){ rcl_tab('sale-links','rcl_tab_salelinks','Ссылки на товары',array('public'=>0,'ajax-load'=>true,'output'=>'actions','class'=>'fa-download')); } function rcl_tab_salelinks($user_id){ global $wpdb; $sales = $wpdb->get_results( "SELECT * FROM ".WP_PREFIX."rmag_files_downloads WHERE user_id = '$user_id' AND count_download='0' AND puttime > DATE_SUB(NOW(), INTERVAL 7 DAY) ORDER BY ID DESC"); if(!$sales) return 'На данный момент, действующих ссылок на заказанные товары нет.'; $links = array(); foreach($sales as $sale){ $fileID = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title='salefile' AND post_parent='$sale->parent_id'"); $safeId = pow($fileID, 2) + $sale->parent_id; $links[$sale->parent_id]['link'] = get_permalink($sale->parent_id).'?action=download&id='.$safeId.'&code='.$sale->uniq_id; $links[$sale->parent_id]['name'] = get_the_title($sale->parent_id); $links[$sale->parent_id]['date'] = $sale->puttime; } $content = '<h3>Действующие ссылки на заказанные товары</h3>'; $content .= '<table>'; $content .= '<tr><td>Товар</td><td>Дата заказа</td></tr>'; foreach($links as $post_id=>$link){ $content .= '<tr><td><a href="'.$link['link'].'">'.$link['name'].'</a></td><td>'.$link['date'].'</td></tr>'; } $content .= '</table>'; return $content; function rcl_the_product_category_tags() { global $wp_query; if ( $wp_query->is_tax( array( 'prodcat' ) ) ) { global $wpdb; $term = get_term_by( 'slug', $wp_query->query_vars['prodcat'], 'prodcat' ); $tags = $wpdb->get_results( "SELECT DISTINCT " . "terms2.term_id as tag_id, " . "terms2.name as tag_name, " . "terms2.slug as tag_slug, " . "t2.count as posts_count " //. "null as tag_link " . "FROM " . "$wpdb->posts as p1 " . "LEFT JOIN $wpdb->term_relationships as r1 ON p1.ID = r1.object_ID " . "LEFT JOIN $wpdb->term_taxonomy as t1 ON r1.term_taxonomy_id = t1.term_taxonomy_id " . "LEFT JOIN $wpdb->terms as terms1 ON t1.term_id = terms1.term_id, " . "$wpdb->posts as p2 " . "LEFT JOIN $wpdb->term_relationships as r2 ON p2.ID = r2.object_ID " . "LEFT JOIN $wpdb->term_taxonomy as t2 ON r2.term_taxonomy_id = t2.term_taxonomy_id " . "LEFT JOIN $wpdb->terms as terms2 ON t2.term_id = terms2.term_id " . "WHERE " . "t1.taxonomy = 'prodcat' AND p1.post_status = 'publish' AND terms1.slug IN ('" . $wp_query->query_vars['prodcat'] . "') AND " . "t2.taxonomy = 'product_tag' AND p2.post_status = 'publish' " . "AND p1.ID = p2.ID " . "AND t2.count > '9'" . "ORDER by posts_count DESC" ); if ( ! $tags ) return false; $content = '<div class="popular-category-tags">'; $content .= 'Популярные метки: '; $tagsArray = array(); foreach ( $tags as $tag ) { $tagsArray[] = '<a href="' . get_term_link( ( int ) $term->term_id, 'prodcat' ) . '?product-tag=' . $tag->tag_slug . '" ' . (isset( $_GET['product-tag'] ) && $_GET['product-tag'] == $tag->tag_slug ? 'class="active-tag"' : '') . '>' . $tag->tag_name . '</a>'; } $content .= implode( ', ', $tagsArray ); $content .= '</div>'; echo $content; } } add_action( 'pre_get_posts', 'pre_get_groups_category_filter' ); function pre_get_groups_category_filter( $query ) { if ( ! is_admin() && $query->is_main_query() ) { if ( $query->is_tax( array( 'prodcat' ) ) && isset( $_GET['product-tag'] ) ) { $query->set( 'tax_query', array( array( 'taxonomy' => 'product_tag', 'field' => 'slug', 'terms' => $_GET['product-tag'] ), array( 'taxonomy' => 'prodcat', 'field' => 'slug', 'terms' => $query->query_vars['prodcat'] ) ) ); } } } }
Hueman Child WP-Recall: Архивы (archive.php)
<?php get_header(); ?> <?php rcl_the_product_category_tags(); ?> <section class="content"> <?php get_template_part('parts/page-title'); ?> <?php rcl_the_product_category_tags(); ?> <div class="pad group"> <?php rcl_the_product_category_tags(); ?> <?php if ((category_description() != '') && !is_paged()) : ?> <div class="notebox"> <?php echo category_description(); ?> </div> <?php endif; ?> <?php rcl_the_product_category_tags(); ?> <?php if(is_post_type_archive('task')||is_tax('task-subject')) echo fng_get_search_form(array('type'=>'horizontal')); ?> <?php if ( have_posts() ) : ?> <?php rcl_the_product_category_tags(); ?> <?php /*if ( hu_is_checked('blog-standard') ): ?> <?php while ( have_posts() ): the_post(); ?> <?php get_template_part('content-standard'); ?> <?php endwhile; ?> <?php else:*/ ?> <div class="post-list group"> <?php $i = 1; echo '<div class="post-row">'; while ( have_posts() ): the_post(); ?> <?php get_template_part('content'); ?> <?php if($i % 2 == 0) { echo '</div><div class="post-row">'; } $i++; endwhile; echo '</div>'; ?> </div><!--/.post-list--> <?php /*endif;*/ ?> <?php rcl_the_product_category_tags(); ?> <?php get_template_part('parts/pagination'); ?> <?php endif; ?> </div><!--/.pad--> </section><!--/.content--> <?php rcl_the_product_category_tags(); ?> <?php get_sidebar(); ?> <?php get_footer(); ?>
Все возможные места вставил код, ничего не вышло.