“Taxonomie- {Taxonomie-Slug} .php” Réponses codées

Obtenez l'ID à terme de taxonomie de Slug - WordPress

<?php 
    $term = get_term_by('slug', $slug, 'category'); 
    $name = $term->name; 
    $id = $term->term_id;
?>
Adventurous Ant

Taxonomie- {Taxonomie-Slug} .php

taxonomy-{taxonomy}-{slug}.php
taxonomy-{taxonomy}.php
taxonomy.php
archive.php
index.php
Weary Wildebeest

Taxonomie- {Taxonomie-Slug} .php

add_action( 'init', 'create_post_type' );
function create_post_type() {
    register_post_type( 'products',
        array(
            'labels' => array(
                'name' => __( 'Products' ),
                'singular_name' => __( 'Product' )
            ),
        'capability_type' => 'post',
        'supports' => array('title','editor','comments'),   
        'public' => true,
        'has_archive' => true,
        'rewrite' => array( 'slug' => 'products' ),
        )
    );
}

function news_init() {
    // create a new taxonomy
    register_taxonomy(
        'products',
        'products',
        array(
            'label' => __( 'Product Categories' ),
            'sort' => true,
            'hierarchical' => true,
            'args' => array( 'orderby' => 'term_order' ),
            'rewrite' => array( 'slug' => 'products-category' )
        )
    );      
}
add_action( 'init', 'news_init' );
Weary Wildebeest

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code