【问题标题】:Displaying products based on the custom taxonomy created根据创建的自定义分类显示产品
【发布时间】:2014-12-10 07:44:05
【问题描述】:

我正在做一个在线商店项目。我创建了一个名为“性别”的 wordpress 自定义分类法,并在其中添加了两个名为 men's 和 women's 的术语,并在产品中添加了分类法。当我添加每个产品时,我选择了分类法ie,either men's or women's.Also created a custom menu to display the taxonomy on the menubar.When I click on men's,the products that were under men's category should display and when select women's,the curresponding products should be displayed.I am new对于 php 和 wordpress,我不知道如何显示与分类术语相关的相应产品。请帮助....

enter code here

<?php
/*
* Plugin Name: Gender Category Tab
* Description: Creates a gender category.
* Version: 1.0.1
*/
if(!defined('ABSPATH')) exit; // Exit if accessed directly

//hook into the init action and call create_gender_hierarchical_taxonomy when it fires

add_action( 'init', 'create_gendercategory_taxonomy', 0 );

function create_gendercategory_taxonomy() {

// Labels part for the GUI

$labels = array(
'name'                      => _x( 'gender', 'taxonomy general name' ),
'singular_name'             => _x( 'gender', 'taxonomy singular name' ),
'search_items'              =>  __( 'Search gender' ),
'popular_items'             => __( 'Popular gender' ),
'all_items'                 => __( 'All gender' ),
'parent_item'               => null,
'parent_item_colon'         => null,
'edit_item'                 => __( 'Edit gender' ), 
'update_item'               => __( 'Update gender' ),
'add_new_item'              => __( 'Add New gender' ),
'new_item_name'             => __( 'New gender Name' ),
'add_or_remove_items'       => __( 'Add or remove gender' ),
'choose_from_most_used'     => __( 'Choose from the most used gender' ),
'menu_name'                 => __( 'gender' ),
 ); 



 register_taxonomy('gender','product',array(
'labels'                    => $labels,
'hierarchical'              => true,
'public'                    => true,
'show_ui'                   => true,
'show_admin_column'         => true,
'show_in_nav_menus'         => true,
'show_tagcloud'             => true,
'query_var'                 => true,
'rewrite'                   => array( 'slug' => 'topic' ),

 ));

} add_filter('wp_nav_menu_items', 'gender_clothing_menu_item',10,2);

function gender_clothing_menu_item( $items, $args ) {
  $taxo_terms = get_terms( 'gender', array(     'hide_empty' => 0) );
  $allProducts=site_url()."/shop";
  $items.="<li class='menu-item menu-item-type-custom menu-item-object-custom menu-item-has-  children dropdown'><a href='".$allProducts."'>Clothings</a>";
 $items.="<ul class='sub-menu'>";
 foreach($taxo_terms as $term)
 {
  $items.='<li class="menu-item menu-item-type-custom menu-item-object-custom"><a href="">'  .$term->name. '</a></li>';
 }
 $items.="</ul>";
 $items.="</li>";

return $items;

 }

 ?>

【问题讨论】:

    标签: javascript wordpress


    【解决方案1】:

    改变

    foreach($taxo_terms as $term)
     {  $term_link = get_term_link( $term );
      $items.='<li class="menu-item menu-item-type-custom menu-item-object-custom"><a href="' . esc_url( $term_link ) . '">'  .$term->name. '</a></li>';
     }
    

    并使用名称在您的主题中创建文件:

    taxonomy-{taxonomy}.php
    

    做代码展示产品

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-15
      • 2019-06-26
      • 2021-07-30
      • 2019-04-24
      • 2011-01-15
      • 2021-12-13
      • 2019-04-25
      • 1970-01-01
      相关资源
      最近更新 更多