URL phân loại tùy chỉnh WordPress

Kevin Leary là một nhà tư vấn WordPress ở Boston, Massachusetts. Anh ấy chuyên về các trang web WordPress tùy chỉnh dành cho các doanh nghiệp có quy mô từ trung bình đến lớn và có nhiều … Thông tin thêm về Kevin ↬

Bản tin email

Email (đập vỡ) của bạn

Mẹo hàng tuần về giao diện người dùng & UX.
Được hơn 200.000 người tin cậy.

  • URL phân loại tùy chỉnh WordPress
    Đập tanConf Freiburg. Tất cả về Web. Ngày 4–6 tháng 9 năm 2023

  • URL phân loại tùy chỉnh WordPress
    Hệ thống thiết kế thành công

  • URL phân loại tùy chỉnh WordPress
    Giao diện người dùng SmashingConf 2023

  • URL phân loại tùy chỉnh WordPress
    Bắt đầu miễn phí
  • URL phân loại tùy chỉnh WordPress

Nội dung phân loại có thể được hiển thị trong một chủ đề bằng cách sử dụng các mẫu phân loại. Trong một mẫu, có nhiều cách để hiển thị dữ liệu của bạn với các chức năng phân loại được tích hợp sẵn

URL phân loại tùy chỉnh WordPress

Phân loại tích hợp

WordPress cung cấp bốn nguyên tắc phân loại tích hợp sẵn

  1. Danh mục (phân cấp),
  2. Thẻ (nhiều mặt),
  3. Liên kết (nhiều mặt),
  4. Menu điều hướng (phân cấp)

Phân loại tùy chỉnh

WordPress cung cấp một phương pháp nhóm nội dung mới bằng cách cho phép bạn tạo các nguyên tắc phân loại tùy chỉnh của riêng mình. Các nhà phát triển cốt lõi đã tạo hàm


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

2 để xử lý công việc nặng nhọc cho chúng tôi. Tất cả những gì bạn phải làm là hiểu cách định cấu hình tất cả các cài đặt cho phù hợp với nhu cầu của mình

Một ví dụ thực tế. Nội dung theo vị trí

Doanh nghiệp hoạt động ở nhiều địa điểm có thể hưởng lợi từ việc tổ chức nội dung theo địa điểm để cho phép khách truy cập duyệt tin tức ở địa phương của họ. Một tổ chức tin tức lớn có thể tổ chức nội dung của mình theo khu vực thế giới (Châu Phi, Châu Á, Châu Âu, Châu Mỹ Latinh, Trung Đông, Hoa Kỳ và Canada), như BBC đã làm trong phần “Thế giới” của mình

URL phân loại tùy chỉnh WordPress

Tạo phân loại tùy chỉnh

Trong WordPress, bạn có thể tạo (hoặc “đăng ký”) một phân loại mới bằng cách sử dụng hàm


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

2. Mỗi tùy chọn phân loại được ghi lại chi tiết trong WordPress Codex

URL phân loại tùy chỉnh WordPress

/**
 * Add custom taxonomies
 *
 * Additional custom taxonomies can be defined here
 * https://codex.wordpress.org/Function_Reference/register_taxonomy
 */
function add_custom_taxonomies() {
  // Add new "Locations" taxonomy to Posts
  register_taxonomy('location', 'post', array(
    // Hierarchical taxonomy (like categories)
    'hierarchical' => true,
    // This array of options controls the labels displayed in the WordPress Admin UI
    'labels' => array(
      'name' => _x( 'Locations', 'taxonomy general name' ),
      'singular_name' => _x( 'Location', 'taxonomy singular name' ),
      'search_items' =>  __( 'Search Locations' ),
      'all_items' => __( 'All Locations' ),
      'parent_item' => __( 'Parent Location' ),
      'parent_item_colon' => __( 'Parent Location:' ),
      'edit_item' => __( 'Edit Location' ),
      'update_item' => __( 'Update Location' ),
      'add_new_item' => __( 'Add New Location' ),
      'new_item_name' => __( 'New Location Name' ),
      'menu_name' => __( 'Locations' ),
    ),
    // Control the slugs used for this taxonomy
    'rewrite' => array(
      'slug' => 'locations', // This controls the base slug that will display before each term
      'with_front' => false, // Don't display the category base before "/locations/"
      'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
    ),
  ));
}
add_action( 'init', 'add_custom_taxonomies', 0 );

Sau khi thêm phần này vào tệp


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

4 của chủ đề, bạn sẽ thấy một phân loại mới trong menu “Bài đăng” trong thanh bên của quản trị viên. Nó hoạt động giống như các danh mục nhưng riêng biệt và độc lập

URL phân loại tùy chỉnh WordPress

Sau khi thêm một vài thuật ngữ vào phân loại mới của bạn, bạn có thể bắt đầu sắp xếp nội dung trong các bài đăng của mình theo vị trí. Một hộp “Vị trí” mới sẽ xuất hiện ở bên phải bài đăng của bạn trong khu vực quản trị WordPress. Sử dụng cái này theo cách bạn sẽ phân loại

Hãy sử dụng phân loại "vị trí" này như một điểm xuất phát để tìm hiểu thêm về cách làm việc với các chức năng và nội dung phân loại

Tạo một mẫu phân loại cho chủ đề của bạn

URL phân loại tùy chỉnh WordPress

Khi bạn thêm phân loại tùy chỉnh vào chủ đề WordPress, bạn có thể hiển thị nội dung của nó bằng một trong các mẫu chủ đề phân loại của WordPress

  • 
    

    name ); ?> News

    description ) ): ?>
    description); ?>
    >

    No News in name ); ?>

    It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

    5 Chúng tôi có thể sử dụng điều này để tạo mẫu chủ đề cho một vị trí cụ thể, chẳng hạn như
    
    

    name ); ?> News

    description ) ): ?>
    description); ?>
    >

    No News in name ); ?>

    It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

    6 cho thuật ngữ “boston. ”
  • 
    

    name ); ?> News

    description ) ): ?>
    description); ?>
    >

    No News in name ); ?>

    It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

    7 Nếu phân loại là
    
    

    name ); ?> News

    description ) ): ?>
    description); ?>
    >

    No News in name ); ?>

    It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

    8, WordPress sẽ tìm kiếm
    
    

    name ); ?> News

    description ) ): ?>
    description); ?>
    >

    No News in name ); ?>

    It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

    9
  • /**
     * Create an unordered list of links to active location archives
     */
    $locations_list = wp_list_categories( array(
      'taxonomy' => 'location',
      'orderby' => 'name',
      'show_count' => 0,
      'pad_counts' => 0,
      'hierarchical' => 1,
      'echo' => 0,
      'title_li' => 'Locations'
    ) );
    
    // Make sure there are terms with articles
    if ( $locations_list )
      echo '
      ' . $locations_list . '
    ';
    0 Mẫu này được sử dụng cho tất cả các nguyên tắc phân loại tùy chỉnh
  • /**
     * Create an unordered list of links to active location archives
     */
    $locations_list = wp_list_categories( array(
      'taxonomy' => 'location',
      'orderby' => 'name',
      'show_count' => 0,
      'pad_counts' => 0,
      'hierarchical' => 1,
      'echo' => 0,
      'title_li' => 'Locations'
    ) );
    
    // Make sure there are terms with articles
    if ( $locations_list )
      echo '
      ' . $locations_list . '
    ';
    1 Nếu không tìm thấy mẫu dành riêng cho phân loại, thì phân loại liệt kê các trang sẽ sử dụng mẫu lưu trữ
  • /**
     * Create an unordered list of links to active location archives
     */
    $locations_list = wp_list_categories( array(
      'taxonomy' => 'location',
      'orderby' => 'name',
      'show_count' => 0,
      'pad_counts' => 0,
      'hierarchical' => 1,
      'echo' => 0,
      'title_li' => 'Locations'
    ) );
    
    // Make sure there are terms with articles
    if ( $locations_list )
      echo '
      ' . $locations_list . '
    ';
    2 Nếu không tìm thấy mẫu nào khác, mẫu này sẽ được sử dụng

Hãy sử dụng


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

9 để hiển thị nội dung của chúng tôi. Tệp mẫu có thể trông giống như thế này


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

(Thông thường, chúng tôi sẽ tải một phần mẫu cho vòng lặp, nhưng để đơn giản, tôi đã bỏ qua bước đó. Thay thế cho

/**
 * Create an unordered list of links to active location archives
 */
$locations_list = wp_list_categories( array(
  'taxonomy' => 'location',
  'orderby' => 'name',
  'show_count' => 0,
  'pad_counts' => 0,
  'hierarchical' => 1,
  'echo' => 0,
  'title_li' => 'Locations'
) );

// Make sure there are terms with articles
if ( $locations_list )
  echo '
    ' . $locations_list . '
';
4, chúng tôi có thể sử dụng
/**
 * Create an unordered list of links to active location archives
 */
$locations_list = wp_list_categories( array(
  'taxonomy' => 'location',
  'orderby' => 'name',
  'show_count' => 0,
  'pad_counts' => 0,
  'hierarchical' => 1,
  'echo' => 0,
  'title_li' => 'Locations'
) );

// Make sure there are terms with articles
if ( $locations_list )
  echo '
    ' . $locations_list . '
';
5 và
/**
 * Create an unordered list of links to active location archives
 */
$locations_list = wp_list_categories( array(
  'taxonomy' => 'location',
  'orderby' => 'name',
  'show_count' => 0,
  'pad_counts' => 0,
  'hierarchical' => 1,
  'echo' => 0,
  'title_li' => 'Locations'
) );

// Make sure there are terms with articles
if ( $locations_list )
  echo '
    ' . $locations_list . '
';
6 trên mẫu lưu trữ phân loại này để hiển thị hoặc truy xuất tiêu đề và mô tả của thuật ngữ phân loại. )

Trong ví dụ này, chúng tôi đã sử dụng một hàm có tên là

/**
 * Create an unordered list of links to active location archives
 */
$locations_list = wp_list_categories( array(
  'taxonomy' => 'location',
  'orderby' => 'name',
  'show_count' => 0,
  'pad_counts' => 0,
  'hierarchical' => 1,
  'echo' => 0,
  'title_li' => 'Locations'
) );

// Make sure there are terms with articles
if ( $locations_list )
  echo '
    ' . $locations_list . '
';
4 để truy xuất tất cả dữ liệu được liên kết với thuật ngữ phân loại ở dạng đối tượng. Đối tượng được trả về bởi hàm
/**
 * Create an unordered list of links to active location archives
 */
$locations_list = wp_list_categories( array(
  'taxonomy' => 'location',
  'orderby' => 'name',
  'show_count' => 0,
  'pad_counts' => 0,
  'hierarchical' => 1,
  'echo' => 0,
  'title_li' => 'Locations'
) );

// Make sure there are terms with articles
if ( $locations_list )
  echo '
    ' . $locations_list . '
';
4 chứa các chi tiết sau về thuật ngữ

  • /**
     * Create an unordered list of links to active location archives
     */
    $locations_list = wp_list_categories( array(
      'taxonomy' => 'location',
      'orderby' => 'name',
      'show_count' => 0,
      'pad_counts' => 0,
      'hierarchical' => 1,
      'echo' => 0,
      'title_li' => 'Locations'
    ) );
    
    // Make sure there are terms with articles
    if ( $locations_list )
      echo '
      ' . $locations_list . '
    ';
    9 325
  • /**
     * Add custom taxonomies
     *
     * Additional custom taxonomies can be defined here
     * https://codex.wordpress.org/Function_Reference/register_taxonomy
     */
    function add_custom_taxonomies() {
      // Add new "Locations" taxonomy to Posts
      register_taxonomy('location', 'post', array(
        // Hierarchical taxonomy (like categories)
        'hierarchical' => true,
        // This array of options controls the labels displayed in the WordPress Admin UI
        'labels' => array(
          'name' => _x( 'Locations', 'taxonomy general name' ),
          'singular_name' => _x( 'Location', 'taxonomy singular name' ),
          'search_items' =>  __( 'Search Locations' ),
          'all_items' => __( 'All Locations' ),
          'parent_item' => __( 'Parent Location' ),
          'parent_item_colon' => __( 'Parent Location:' ),
          'edit_item' => __( 'Edit Location' ),
          'update_item' => __( 'Update Location' ),
          'add_new_item' => __( 'Add New Location' ),
          'new_item_name' => __( 'New Location Name' ),
          'menu_name' => __( 'Locations' ),
        ),
        // Control the slugs used for this taxonomy
        'rewrite' => array(
          'slug' => 'locations', // This controls the base slug that will display before each term
          'with_front' => false, // Don't display the category base before "/locations/"
          'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
        ),
      ));
    }
    add_action( 'init', 'add_custom_taxonomies', 0 );
    00 Boston
  • /**
     * Add custom taxonomies
     *
     * Additional custom taxonomies can be defined here
     * https://codex.wordpress.org/Function_Reference/register_taxonomy
     */
    function add_custom_taxonomies() {
      // Add new "Locations" taxonomy to Posts
      register_taxonomy('location', 'post', array(
        // Hierarchical taxonomy (like categories)
        'hierarchical' => true,
        // This array of options controls the labels displayed in the WordPress Admin UI
        'labels' => array(
          'name' => _x( 'Locations', 'taxonomy general name' ),
          'singular_name' => _x( 'Location', 'taxonomy singular name' ),
          'search_items' =>  __( 'Search Locations' ),
          'all_items' => __( 'All Locations' ),
          'parent_item' => __( 'Parent Location' ),
          'parent_item_colon' => __( 'Parent Location:' ),
          'edit_item' => __( 'Edit Location' ),
          'update_item' => __( 'Update Location' ),
          'add_new_item' => __( 'Add New Location' ),
          'new_item_name' => __( 'New Location Name' ),
          'menu_name' => __( 'Locations' ),
        ),
        // Control the slugs used for this taxonomy
        'rewrite' => array(
          'slug' => 'locations', // This controls the base slug that will display before each term
          'with_front' => false, // Don't display the category base before "/locations/"
          'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
        ),
      ));
    }
    add_action( 'init', 'add_custom_taxonomies', 0 );
    01 boston
  • /**
     * Add custom taxonomies
     *
     * Additional custom taxonomies can be defined here
     * https://codex.wordpress.org/Function_Reference/register_taxonomy
     */
    function add_custom_taxonomies() {
      // Add new "Locations" taxonomy to Posts
      register_taxonomy('location', 'post', array(
        // Hierarchical taxonomy (like categories)
        'hierarchical' => true,
        // This array of options controls the labels displayed in the WordPress Admin UI
        'labels' => array(
          'name' => _x( 'Locations', 'taxonomy general name' ),
          'singular_name' => _x( 'Location', 'taxonomy singular name' ),
          'search_items' =>  __( 'Search Locations' ),
          'all_items' => __( 'All Locations' ),
          'parent_item' => __( 'Parent Location' ),
          'parent_item_colon' => __( 'Parent Location:' ),
          'edit_item' => __( 'Edit Location' ),
          'update_item' => __( 'Update Location' ),
          'add_new_item' => __( 'Add New Location' ),
          'new_item_name' => __( 'New Location Name' ),
          'menu_name' => __( 'Locations' ),
        ),
        // Control the slugs used for this taxonomy
        'rewrite' => array(
          'slug' => 'locations', // This controls the base slug that will display before each term
          'with_front' => false, // Don't display the category base before "/locations/"
          'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
        ),
      ));
    }
    add_action( 'init', 'add_custom_taxonomies', 0 );
    02 0
  • địa điểm
    /**
     * Add custom taxonomies
     *
     * Additional custom taxonomies can be defined here
     * https://codex.wordpress.org/Function_Reference/register_taxonomy
     */
    function add_custom_taxonomies() {
      // Add new "Locations" taxonomy to Posts
      register_taxonomy('location', 'post', array(
        // Hierarchical taxonomy (like categories)
        'hierarchical' => true,
        // This array of options controls the labels displayed in the WordPress Admin UI
        'labels' => array(
          'name' => _x( 'Locations', 'taxonomy general name' ),
          'singular_name' => _x( 'Location', 'taxonomy singular name' ),
          'search_items' =>  __( 'Search Locations' ),
          'all_items' => __( 'All Locations' ),
          'parent_item' => __( 'Parent Location' ),
          'parent_item_colon' => __( 'Parent Location:' ),
          'edit_item' => __( 'Edit Location' ),
          'update_item' => __( 'Update Location' ),
          'add_new_item' => __( 'Add New Location' ),
          'new_item_name' => __( 'New Location Name' ),
          'menu_name' => __( 'Locations' ),
        ),
        // Control the slugs used for this taxonomy
        'rewrite' => array(
          'slug' => 'locations', // This controls the base slug that will display before each term
          'with_front' => false, // Don't display the category base before "/locations/"
          'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
        ),
      ));
    }
    add_action( 'init', 'add_custom_taxonomies', 0 );
    03
  • /**
     * Add custom taxonomies
     *
     * Additional custom taxonomies can be defined here
     * https://codex.wordpress.org/Function_Reference/register_taxonomy
     */
    function add_custom_taxonomies() {
      // Add new "Locations" taxonomy to Posts
      register_taxonomy('location', 'post', array(
        // Hierarchical taxonomy (like categories)
        'hierarchical' => true,
        // This array of options controls the labels displayed in the WordPress Admin UI
        'labels' => array(
          'name' => _x( 'Locations', 'taxonomy general name' ),
          'singular_name' => _x( 'Location', 'taxonomy singular name' ),
          'search_items' =>  __( 'Search Locations' ),
          'all_items' => __( 'All Locations' ),
          'parent_item' => __( 'Parent Location' ),
          'parent_item_colon' => __( 'Parent Location:' ),
          'edit_item' => __( 'Edit Location' ),
          'update_item' => __( 'Update Location' ),
          'add_new_item' => __( 'Add New Location' ),
          'new_item_name' => __( 'New Location Name' ),
          'menu_name' => __( 'Locations' ),
        ),
        // Control the slugs used for this taxonomy
        'rewrite' => array(
          'slug' => 'locations', // This controls the base slug that will display before each term
          'with_front' => false, // Don't display the category base before "/locations/"
          'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
        ),
      ));
    }
    add_action( 'init', 'add_custom_taxonomies', 0 );
    04 325
  • /**
     * Add custom taxonomies
     *
     * Additional custom taxonomies can be defined here
     * https://codex.wordpress.org/Function_Reference/register_taxonomy
     */
    function add_custom_taxonomies() {
      // Add new "Locations" taxonomy to Posts
      register_taxonomy('location', 'post', array(
        // Hierarchical taxonomy (like categories)
        'hierarchical' => true,
        // This array of options controls the labels displayed in the WordPress Admin UI
        'labels' => array(
          'name' => _x( 'Locations', 'taxonomy general name' ),
          'singular_name' => _x( 'Location', 'taxonomy singular name' ),
          'search_items' =>  __( 'Search Locations' ),
          'all_items' => __( 'All Locations' ),
          'parent_item' => __( 'Parent Location' ),
          'parent_item_colon' => __( 'Parent Location:' ),
          'edit_item' => __( 'Edit Location' ),
          'update_item' => __( 'Update Location' ),
          'add_new_item' => __( 'Add New Location' ),
          'new_item_name' => __( 'New Location Name' ),
          'menu_name' => __( 'Locations' ),
        ),
        // Control the slugs used for this taxonomy
        'rewrite' => array(
          'slug' => 'locations', // This controls the base slug that will display before each term
          'with_front' => false, // Don't display the category base before "/locations/"
          'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
        ),
      ));
    }
    add_action( 'init', 'add_custom_taxonomies', 0 );
    05 Nếu bạn cần biết những tin tức mới nhất ở Boston, thì không cần tìm đâu xa
  • /**
     * Add custom taxonomies
     *
     * Additional custom taxonomies can be defined here
     * https://codex.wordpress.org/Function_Reference/register_taxonomy
     */
    function add_custom_taxonomies() {
      // Add new "Locations" taxonomy to Posts
      register_taxonomy('location', 'post', array(
        // Hierarchical taxonomy (like categories)
        'hierarchical' => true,
        // This array of options controls the labels displayed in the WordPress Admin UI
        'labels' => array(
          'name' => _x( 'Locations', 'taxonomy general name' ),
          'singular_name' => _x( 'Location', 'taxonomy singular name' ),
          'search_items' =>  __( 'Search Locations' ),
          'all_items' => __( 'All Locations' ),
          'parent_item' => __( 'Parent Location' ),
          'parent_item_colon' => __( 'Parent Location:' ),
          'edit_item' => __( 'Edit Location' ),
          'update_item' => __( 'Update Location' ),
          'add_new_item' => __( 'Add New Location' ),
          'new_item_name' => __( 'New Location Name' ),
          'menu_name' => __( 'Locations' ),
        ),
        // Control the slugs used for this taxonomy
        'rewrite' => array(
          'slug' => 'locations', // This controls the base slug that will display before each term
          'with_front' => false, // Don't display the category base before "/locations/"
          'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
        ),
      ));
    }
    add_action( 'init', 'add_custom_taxonomies', 0 );
    06 0 (hoặc ID)
  • /**
     * Add custom taxonomies
     *
     * Additional custom taxonomies can be defined here
     * https://codex.wordpress.org/Function_Reference/register_taxonomy
     */
    function add_custom_taxonomies() {
      // Add new "Locations" taxonomy to Posts
      register_taxonomy('location', 'post', array(
        // Hierarchical taxonomy (like categories)
        'hierarchical' => true,
        // This array of options controls the labels displayed in the WordPress Admin UI
        'labels' => array(
          'name' => _x( 'Locations', 'taxonomy general name' ),
          'singular_name' => _x( 'Location', 'taxonomy singular name' ),
          'search_items' =>  __( 'Search Locations' ),
          'all_items' => __( 'All Locations' ),
          'parent_item' => __( 'Parent Location' ),
          'parent_item_colon' => __( 'Parent Location:' ),
          'edit_item' => __( 'Edit Location' ),
          'update_item' => __( 'Update Location' ),
          'add_new_item' => __( 'Add New Location' ),
          'new_item_name' => __( 'New Location Name' ),
          'menu_name' => __( 'Locations' ),
        ),
        // Control the slugs used for this taxonomy
        'rewrite' => array(
          'slug' => 'locations', // This controls the base slug that will display before each term
          'with_front' => false, // Don't display the category base before "/locations/"
          'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
        ),
      ));
    }
    add_action( 'init', 'add_custom_taxonomies', 0 );
    07 1 (tôi. e. số lượng bài viết với cụm từ này được chọn)

Sau đó, chúng tôi đã sử dụng đối tượng này để hiển thị thông tin về thuật ngữ hiện tại

/**
 * Add custom taxonomies
 *
 * Additional custom taxonomies can be defined here
 * https://codex.wordpress.org/Function_Reference/register_taxonomy
 */
function add_custom_taxonomies() {
  // Add new "Locations" taxonomy to Posts
  register_taxonomy('location', 'post', array(
    // Hierarchical taxonomy (like categories)
    'hierarchical' => true,
    // This array of options controls the labels displayed in the WordPress Admin UI
    'labels' => array(
      'name' => _x( 'Locations', 'taxonomy general name' ),
      'singular_name' => _x( 'Location', 'taxonomy singular name' ),
      'search_items' =>  __( 'Search Locations' ),
      'all_items' => __( 'All Locations' ),
      'parent_item' => __( 'Parent Location' ),
      'parent_item_colon' => __( 'Parent Location:' ),
      'edit_item' => __( 'Edit Location' ),
      'update_item' => __( 'Update Location' ),
      'add_new_item' => __( 'Add New Location' ),
      'new_item_name' => __( 'New Location Name' ),
      'menu_name' => __( 'Locations' ),
    ),
    // Control the slugs used for this taxonomy
    'rewrite' => array(
      'slug' => 'locations', // This controls the base slug that will display before each term
      'with_front' => false, // Don't display the category base before "/locations/"
      'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
    ),
  ));
}
add_action( 'init', 'add_custom_taxonomies', 0 );
00 và
/**
 * Add custom taxonomies
 *
 * Additional custom taxonomies can be defined here
 * https://codex.wordpress.org/Function_Reference/register_taxonomy
 */
function add_custom_taxonomies() {
  // Add new "Locations" taxonomy to Posts
  register_taxonomy('location', 'post', array(
    // Hierarchical taxonomy (like categories)
    'hierarchical' => true,
    // This array of options controls the labels displayed in the WordPress Admin UI
    'labels' => array(
      'name' => _x( 'Locations', 'taxonomy general name' ),
      'singular_name' => _x( 'Location', 'taxonomy singular name' ),
      'search_items' =>  __( 'Search Locations' ),
      'all_items' => __( 'All Locations' ),
      'parent_item' => __( 'Parent Location' ),
      'parent_item_colon' => __( 'Parent Location:' ),
      'edit_item' => __( 'Edit Location' ),
      'update_item' => __( 'Update Location' ),
      'add_new_item' => __( 'Add New Location' ),
      'new_item_name' => __( 'New Location Name' ),
      'menu_name' => __( 'Locations' ),
    ),
    // Control the slugs used for this taxonomy
    'rewrite' => array(
      'slug' => 'locations', // This controls the base slug that will display before each term
      'with_front' => false, // Don't display the category base before "/locations/"
      'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
    ),
  ));
}
add_action( 'init', 'add_custom_taxonomies', 0 );
05 trong mẫu

name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

9

Sử dụng điều kiện phân loại

Thẻ có điều kiện có thể được sử dụng trong WordPress để xác định nội dung nào được hiển thị trên một trang cụ thể tùy thuộc vào các điều kiện mà trang đáp ứng. Các mẫu phân loại có bộ điều kiện riêng

  • 
    

    name ); ?> News

    description ) ): ?>
    description); ?>
    >

    No News in name ); ?>

    It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

    11 Khi bất kỳ trang lưu trữ phân loại nào đang được hiển thị
  • 
    

    name ); ?> News

    description ) ): ?>
    description); ?>
    >

    No News in name ); ?>

    It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

    12 Khi một trang lưu trữ phân loại cho phân loại "vị trí" đang được hiển thị
  • 
    

    name ); ?> News

    description ) ): ?>
    description); ?>
    >

    No News in name ); ?>

    It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

    13 Khi trang lưu trữ cho phân loại "vị trí" với sên "boston" đang được hiển thị
  • 
    

    name ); ?> News

    description ) ): ?>
    description); ?>
    >

    No News in name ); ?>

    It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

    14 Trả về
    
    

    name ); ?> News

    description ) ): ?>
    description); ?>
    >

    No News in name ); ?>

    It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

    15 khi kho lưu trữ phân loại "vị trí" đang được hiển thị có một con sên là "boston", "new-york" hoặc "philadelphia. ”
  • 
    

    name ); ?> News

    description ) ): ?>
    description); ?>
    >

    No News in name ); ?>

    It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

    16 Khi một phân loại cụ thể được đăng ký qua
    
    

    name ); ?> News

    description ) ): ?>
    description); ?>
    >

    No News in name ); ?>

    It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

    2

Làm việc với các chức năng phân loại

Nhiều chức năng để làm việc với các nguyên tắc phân loại có sẵn trong WordPress. Hãy xem qua một số ví dụ phổ biến về cách sử dụng chúng trong thực tế

Hiển thị danh sách các thuật ngữ phân loại

Hầu hết các hệ thống điều hướng bắt đầu với một danh sách không có thứ tự. Bạn có thể tạo danh sách liên kết không theo thứ tự đến các trang lưu trữ phân loại bằng cách sử dụng hàm


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

18. Chức năng này rất dễ tùy chỉnh và có thể xử lý hầu hết các tình huống mà bạn sẽ gặp phải với tư cách là nhà phát triển chủ đề

/**
 * Create an unordered list of links to active location archives
 */
$locations_list = wp_list_categories( array(
  'taxonomy' => 'location',
  'orderby' => 'name',
  'show_count' => 0,
  'pad_counts' => 0,
  'hierarchical' => 1,
  'echo' => 0,
  'title_li' => 'Locations'
) );

// Make sure there are terms with articles
if ( $locations_list )
  echo '
    ' . $locations_list . '
';

Nếu bạn gặp tình huống yêu cầu cấu trúc tùy chỉnh, tôi khuyên bạn nên khám phá lớp Walker hoặc hàm


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

19

Tạo một đám mây thẻ phân loại

Đám mây thẻ cung cấp một cách tuyệt vời để người dùng duyệt nội dung. Hàm


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

10 giúp tạo đám mây thẻ với phân loại tùy chỉnh dễ dàng

URL phân loại tùy chỉnh WordPress

Hãy sử dụng nó để hiển thị một đám mây thẻ các cụm từ vị trí của chúng tôi

/**
 * Add custom taxonomies
 *
 * Additional custom taxonomies can be defined here
 * https://codex.wordpress.org/Function_Reference/register_taxonomy
 */
function add_custom_taxonomies() {
  // Add new "Locations" taxonomy to Posts
  register_taxonomy('location', 'post', array(
    // Hierarchical taxonomy (like categories)
    'hierarchical' => true,
    // This array of options controls the labels displayed in the WordPress Admin UI
    'labels' => array(
      'name' => _x( 'Locations', 'taxonomy general name' ),
      'singular_name' => _x( 'Location', 'taxonomy singular name' ),
      'search_items' =>  __( 'Search Locations' ),
      'all_items' => __( 'All Locations' ),
      'parent_item' => __( 'Parent Location' ),
      'parent_item_colon' => __( 'Parent Location:' ),
      'edit_item' => __( 'Edit Location' ),
      'update_item' => __( 'Update Location' ),
      'add_new_item' => __( 'Add New Location' ),
      'new_item_name' => __( 'New Location Name' ),
      'menu_name' => __( 'Locations' ),
    ),
    // Control the slugs used for this taxonomy
    'rewrite' => array(
      'slug' => 'locations', // This controls the base slug that will display before each term
      'with_front' => false, // Don't display the category base before "/locations/"
      'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
    ),
  ));
}
add_action( 'init', 'add_custom_taxonomies', 0 );
0

Nhận tất cả các điều khoản trong phân loại

Bạn sẽ thường xuyên phải làm việc với danh sách đầy đủ các thuật ngữ trong phân loại và hàm


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

11 có thể khá hữu ích cho việc này. Hãy sử dụng nó để hiển thị số lượng địa điểm mà chúng tôi đang cung cấp tin tức


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

1

Điều này sẽ xuất HTML sau


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

1

Cách tiếp cận đơn giản này có thể không hiển thị, nhưng chức năng


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

11 cực kỳ mạnh mẽ. Nó cho phép bạn nhận các thuật ngữ từ nhiều nguyên tắc phân loại cùng một lúc bằng cách chuyển một mảng chứa tên của các nguyên tắc phân loại của bạn làm tham số đầu tiên

Làm việc với WP_Query và tax_query

Lớp


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

13 cho phép bạn tạo một vòng lặp tùy chỉnh. wordpress 3. 1 đã giới thiệu một tham số mới cho lớp có tên là

name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

1, cho phép bạn hiển thị nội dung từ phân loại theo nhiều cách độc đáo

Hãy sử dụng nó để tạo một danh sách các bài đăng tin tức gần đây nhất ở Boston


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

9

Chúng ta có thể dễ dàng làm cho thiết lập này trở nên năng động bằng cách sử dụng các hàm

/**
 * Create an unordered list of links to active location archives
 */
$locations_list = wp_list_categories( array(
  'taxonomy' => 'location',
  'orderby' => 'name',
  'show_count' => 0,
  'pad_counts' => 0,
  'hierarchical' => 1,
  'echo' => 0,
  'title_li' => 'Locations'
) );

// Make sure there are terms with articles
if ( $locations_list )
  echo '
    ' . $locations_list . '
';
4 hoặc

name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

11 mà chúng ta đã thảo luận trước đó

Đính kèm dữ liệu bổ sung vào phân loại

Mỗi thuật ngữ phân loại có dữ liệu cụ thể liên quan đến nó. Ngoài hộp, WordPress cho phép bạn lưu trữ các thông tin sau cho từng thuật ngữ phân loại

  • Tên,
  • sên,
  • Cha mẹ,
  • Sự miêu tả

Nhưng điều gì sẽ xảy ra nếu bạn cần lưu trữ thêm thông tin, chẳng hạn như hình ảnh cho thuật ngữ phân loại hoặc tiêu đề và mô tả cho công cụ tìm kiếm hoặc thậm chí có thể đính kèm thuật ngữ cho một tác giả cụ thể theo cách mà một cột tin tức truyền thống thực hiện? . 9, các nhà phát triển đã có thể đính kèm dữ liệu meta bổ sung vào các bài đăng, trang, loại bài đăng tùy chỉnh, nhận xét và người dùng bằng cách sử dụng các hàm


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

17,

name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

18 và

name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

19. Nhưng điều này không bao gồm các nguyên tắc phân loại như thẻ và danh mục

Với sự trợ giúp của plugin Siêu dữ liệu phân loại, chúng tôi có thể đính kèm dữ liệu meta vào các thuật ngữ phân loại cho cả phân loại tích hợp và tùy chỉnh. Điều này cho phép chúng tôi tạo các trường phân loại bổ sung sẽ được lưu trữ trong bảng cơ sở dữ liệu


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

90 mới

Lưu ý cho nhà phát triển Multisite. Tôi đã gặp sự cố khi sử dụng plugin Siêu dữ liệu phân loại trên bản cài đặt WordPress Multisite. Kích hoạt plugin trên toàn mạng dẫn đến dữ liệu không được lưu. Thay vào đó, hãy kích hoạt plugin riêng lẻ cho từng trang web và nó sẽ hoạt động bình thường

(Biết câu chuyện đằng sau kỹ thuật này và ý nghĩa của nó đối với các bản nâng cấp WordPress trong tương lai là rất quan trọng. Hiện tại, có một cuộc tranh luận trên dự án WordPress Trac về phương pháp tốt nhất cho việc này. Phương pháp tôi sẽ chỉ cho bạn là phương pháp được đề xuất bởi nhiều nhà phát triển cốt lõi của WordPress. Nhưng tôi thực sự khuyên bạn nên xem lại dự án Trac và Codex. Một cách tiếp cận tiêu chuẩn rất có thể được tích hợp vào WordPress trong tương lai, do đó sẽ thực tế hơn những gì tôi sắp chỉ cho bạn. )

Điều kiện tiên quyết cho tất cả các ví dụ bên dưới là cài đặt và kích hoạt plugin Siêu dữ liệu phân loại

Thêm các trường Tiêu đề và Mô tả của Công cụ Tìm kiếm vào Danh mục và Thẻ

Chúng tôi sẽ sử dụng các hook hành động để đính kèm các trường bổ sung một cách duyên dáng vào các nguyên tắc phân loại của chúng tôi mà không cần chỉnh sửa lõi của WordPress. Nếu bạn đã làm được đến đây, thì có lẽ bạn đã có kiến ​​thức về các bộ lọc và hành động của WordPress. Để tìm hiểu về cách làm việc với móc câu, tôi thực sự khuyên bạn nên đọc bài viết của Daniel Pataki về chủ đề này

URL phân loại tùy chỉnh WordPress

Hãy bắt đầu bằng cách thêm một văn bản


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

91 và một trường

name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

92 vào các trang thuật ngữ “Thêm mới” và “Chỉnh sửa” trên màn hình quản trị WordPress. Chúng tôi làm điều này bằng cách đặt các chức năng sau trong chủ đề hoặc plugin của chúng tôi

Hàm


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

93 gắn các trường vào trang

name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

94. Mục

name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

95 trong URL ở trên sẽ thay đổi tùy thuộc vào cụm từ bạn đang chỉnh sửa


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

1

Hàm


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

96 gắn các trường vào trang

name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

97. Các mục

name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

95,

name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

99 và

name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

10 trong URL ở trên sẽ thay đổi tùy thuộc vào thuật ngữ bạn đang chỉnh sửa

Chúng tôi sẽ sử dụng chức năng


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

11 ở đây để hiển thị bất kỳ dữ liệu đã lưu nào tồn tại trong biểu mẫu


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

8

Hai chức năng này kiểm soát đầu ra của các trường biểu mẫu. Tôi đã sử dụng HTML tuân theo các nguyên tắc về kiểu và kiểu giao diện người dùng của WordPress cho khu vực quản trị

Lưu dữ liệu của biểu mẫu vào bảng cơ sở dữ liệu


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

90 Bây giờ chúng ta đã thêm các trường biểu mẫu, chúng ta sẽ cần xử lý và lưu dữ liệu bằng hàm

name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

13 được cung cấp bởi plugin


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

1

Thêm các trường phân loại mới Bây giờ mọi thứ đã sẵn sàng, chúng tôi sẽ sử dụng móc hành động để tải các chức năng mới của chúng tôi ở tất cả các vị trí phù hợp. Bằng cách nối chức năng sau vào hành động


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

14, chúng tôi đảm bảo rằng nó chỉ chạy ở phía quản trị viên của WordPress. Trước tiên, chúng tôi cần đảm bảo rằng các chức năng được bổ sung bởi plugin Siêu dữ liệu phân loại có sẵn. Tiếp theo, chúng tôi sử dụng hàm

name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

15 để đính kèm các trường phân loại mới vào mọi phân loại công khai, bao gồm các thẻ và danh mục tích hợp


name ); ?> News

description ) ): ?>
description); ?>
>

No News in name ); ?>

It seems there isn't anything happening in name ); ?> right now. Check back later, something is bound to happen soon.

0

Đó là nó. Đã được thực hiện

Bây giờ, bạn sẽ thấy hai trường bổ sung trong thẻ, danh mục và phân loại tùy chỉnh công khai của mình. Như đã đề cập ở đầu phần này, kỹ thuật này có thể được sử dụng để xử lý nhiều tình huống khác nhau. Khung cơ bản này để lưu trữ và truy xuất thông tin liên quan đến phân loại sẽ giúp bạn thành thạo việc quản lý nội dung phân loại

Tóm lại là

Tôi hy vọng bạn hiểu rõ hơn về cách tổ chức nội dung WordPress với sự trợ giúp của các nguyên tắc phân loại. Cho dù là phân cấp hay đa diện, một hệ thống phân loại được triển khai tốt sẽ đơn giản hóa cách tổ chức và hiển thị nội dung trên một trang web. WordPress có tất cả các công cụ bạn cần để tạo phân loại tùy chỉnh và nhóm nội dung của bạn theo những cách mới và thú vị. Làm thế nào bạn sử dụng chúng là tùy thuộc vào bạn