0

Currently i have create :

  • One new taxonomy : project
  • One new post type : task

And i want to have :

// 1- List of all project
www.example.com/projets/

// 2- See one project and list task
www.example.com/projet/un-projet/

// 3- See one task of one project
www.example.com/projet/un-projet/introduction/

Number 1 and 2 don't work. How i can do this?

EDIT :

I have add this in my functions.php

<?php

add_action( 'init', 'tache_type_register' );
/**
 * Ajoute un type de post "Les Tâches" d'un projet
 * @link http://codex.wordpress.org/Function_Reference/register_post_type
 */
function tache_type_register() {
    $labels = array(
        'name'               => 'Tâches',
        'singular_name'      => 'Tâche',
        'menu_name'          => 'Tâches',
        'name_admin_bar'     => 'Tâche',
        'add_new'            => 'Ajouter',
        'add_new_item'       => 'Ajouter une nouvelle tâche',
        'new_item'           => 'Nouvelle tâche',
        'edit_item'          => 'Modifier la tâche',
        'view_item'          => 'Voir la tâche',
        'all_items'          => 'Toutes les tâches',
        'search_items'       => 'Rechercher une tâche',
        'parent_item_colon'  => 'Tâche parente:',
        'not_found'          => 'Aucune tâche trouvée.',
        'not_found_in_trash' => 'Aucune tâche dans la corbeille.',
    );

    $args = array(
        'labels'             => $labels,
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'rewrite'            => array( 'slug' => 'projet/%projet%' ),
        'capability_type'    => 'post',
        'has_archive'        => true,
        'hierarchical'       => false,
        'menu_position'      => 5,
        'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
        //'taxonomies'       => array( 'category', 'post_tag' )
    );

    register_post_type( 'tache', $args );
}


add_action( 'init', 'create_projet_taxonomies' );
/**
 * Ajoute une taxonomie Type pour les pour les Projets
 * @link http://codex.wordpress.org/Function_Reference/register_taxonomy
 */
function create_projet_taxonomies() {

    $labels = array(
        'name'              => 'Projets',
        'singular_name'     => 'Projet',
        'search_items'      => 'Rechercher un projet',
        'all_items'         => 'Tous les projets',
        'parent_item'       => null,
        'parent_item_colon' => null,
        'edit_item'         => 'Modifier un projet',
        'update_item'       => 'Mettre à jour',
        'add_new_item'      => 'Ajouter un nouveau projet',
        'new_item_name'     => 'New Genre Name',
        'menu_name'         => 'Projets',
    );

    $args = array(
        'hierarchical'      => true,
        'labels'            => $labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'i/dont/know/here' ), 
    );

    register_taxonomy( 'projet', array( 'tache' ), $args );
}



/* Filtre pour modifier le permalink Projet */
add_filter('post_link', 'projet_permalink', 1, 3);
add_filter('post_type_link', 'projet_permalink', 1, 3);

function projet_permalink($permalink, $post_id, $leavename) {

    if (strpos($permalink, '%projet%') === FALSE) return $permalink;

        // Get post
        $post = get_post($post_id);
        if (!$post) return $permalink;

        // Get taxonomy terms
        $terms = wp_get_object_terms($post->ID, 'projet');
        if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0]))
            $taxonomy_slug = $terms[0]->slug;
        else $taxonomy_slug = 'no-projet';

    return str_replace('%projet%', $taxonomy_slug, $permalink);
}


?>

and now :

see one task of project like (www.example.com/projet/homepi/introduction/) work
see all task of project like (www.example.com/projet/homepi/) work
but see all project like (www.example.com/projet/) don't work

and don't know about param rewrite of create_projet_taxonomy().

Someone can help me and explain how i can do this ? thanks

Emmanuel Loisance
  • 706
  • 1
  • 12
  • 22

0 Answers0