Forum Replies Created

Viewing 9 replies - 1 through 9 (of 9 total)
  • you can use # for the link href attribute and then check for the ‘ad_hock’ CSS class generated by wordpress to target this type of link. It could be something like ‘menu-item-has-children’.
    And then use jquery like this:
    $(‘ul > .menu-item-has-children’).on(‘click’, function(e) {
    e.preventDefault();
    }

    then, clicking on this type of link will do nothing…

    Thread Starter wp-lionel

    (@wp-lionel)

    No, just in the original theme, and the only constraint in this case is to put back the line in the header.php if you ever update the theme.

    Thread Starter wp-lionel

    (@wp-lionel)

    I’ve found a solution as not making child theme, by addind a line like
    <?php include (TEMPLATEPATH . ‘/my_header_include.php’); ?>
    in the header.php, just before the </head> tag (and after the wp_head() tag)
    in the included file I put a link like
    <link rel=”stylesheet” type=”text/css” href=”<?php echo get_template_directory_uri(); ?>/framework/css/perso.css” />

    The perso.css styles are loaded at the end and I can put in it my additionnal styles.

    Thread Starter wp-lionel

    (@wp-lionel)

    Thanks, but what happen’s if the theme is updated?

    maybe it can exist a solution with a plugin wich just load the stylesheet?

    but how to choose the correct hook toad the stylesheet on?

    did you try to put your own styles in yur child theme?

    Thread Starter wp-lionel

    (@wp-lionel)

    I have fixed the problem..

    it was due to white lines after the closing ?> of the index.php file from the plugin…

    ??

    Thread Starter wp-lionel

    (@wp-lionel)

    I don’t need your generator site ..

    my custom type and taoxonomy WORKS !! the problem is with the interface of WordPress

    Thread Starter wp-lionel

    (@wp-lionel)

    Thanks Anshu but the problem is not with custom post types…

    the problem is with custom taxonomy in fact ??

    Thread Starter wp-lionel

    (@wp-lionel)

    here is the code if eventualy someone who wants to make test

    <?php
    /*
    Plugin Name: lg-vehicules
    Description: Déclare les types de contenus personnalisés "véhicules"
    Version: 1.0
    Author: lui même
    */
    
    /* fonction général flush rewrite   */
    function my_plugin_deactivate()  {
        flush_rewrite_rules();
    }
    
    // ========================================================================
    // ----------------------déclaration custom post type  véhicules-----------
    // ========================================================================
    
    function lgib_create_vehicules()  {
      $labels = array(
        'name' => 'Véhicules',
        'singular_name' => 'Véhicule',
        'add_new' => 'Ajouter',
        'add_new_item' => 'Ajouter un véhicule',
        'edit_item' => 'Modifier un véhicule',
        'new_item' => 'Nouveau Véhicule',
        'all_items' => 'Tous les Véhicules',
        'view_item' => 'Voir le véhicule',
        'search_items' => 'Chercher des véhicules',
        'not_found' => 'Aucun Véhicule trouvé',
        'not_found_in_trash' => 'Aucun Véhicule dans la corbeille',
        'menu_name' => 'Véhicules'
      );
    
      $args = array(
        'labels' => $labels,
        'description' => 'contient toutes les caractéristiques d\'un véhicule',
        'public' => true,
        'has_archive' => true,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'vehicule'),
        'capability_type' => 'post',
        'show_in_menu' => true,
        'show_in_admin_bar' => true,
        'menu_position' => 20,
        'menu_icon' => get_bloginfo('wpurl'). '/wp-content/plugins/vehicules/images/car-icon-16.png',
        'supports' => array('title', 'thumbnail', 'page-attributes', 'author'),
        'can_export' => true
      );
    
      register_post_type( 'lgib_vehicule', $args);
    }
    
    function vehicule_rewrite_flush()  {
      lgib_create_vehicules();
      flush_rewrite_rules();
    }
    
    add_action('init', 'lgib_create_vehicules');
    register_activation_hook(__FILE__, 'vehicule_rewrite_flush');
    register_deactivation_hook(__FILE__, 'my_plugin_deactivate');
    
    // ========================================================================
    // ------------ messages associés au  custom-post-type véhicule-----------
    // ========================================================================
    function lgib_vehicule_updated_messages( $messages ) {
      global $post, $post_ID;
    
      $messages['lgib_vehicule'] = array(
        0 => '', // Unused. Messages start at index 1.
    
        1 => sprintf( 'Véhicule mis à jour. <a href="%s">Voir le Véhicule</a>', esc_url( get_permalink($post_ID) ) ),
    
        2 => 'Champ personnalisé mis à jour',
        3 => 'Champ personnalisé supprimé',
        4 => 'Véhicule mis à jour',
        /* translators: %s: date and time of the revision */
        5 => isset($_GET['revision']) ? sprintf( __('Véhicule restored to revision from %s', 'your_text_domain'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
        6 => sprintf( __('véhicule published. <a href="%s">View book</a>', 'your_text_domain'), esc_url( get_permalink($post_ID) ) ),
        7 => __('Book saved.', 'your_text_domain'),
        8 => sprintf( __('Book submitted. <a target="_blank" href="%s">Preview book</a>', 'your_text_domain'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
        9 => sprintf( __('Book scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview book</a>', 'your_text_domain'),
          // translators: Publish box date format, see https://php.net/date
          date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
        10 => sprintf( __('Book draft updated. <a target="_blank" href="%s">Preview book</a>', 'your_text_domain'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
      );
    
      return $messages;
    }
    add_filter( 'post_updated_messages', 'lgib_vehicule_updated_messages' );
    
    // ==================================================== mise en place de l'aide
    function lgib_vehicule_add_help_text($contextual_help, $screen_id, $screen) {
        if ( 'lgib_vehicule' == $screen->id )  {
            $contextual_help = '<p>Ici l\'aide basique</p>';
        } else if ( 'edit-lgib_vehicule' == $screen->id ) {
            $contextual_help = '<p>aide (edit) </p>';
        } else if ( 'edit-lgib_type' == $screen->id ) {
            $contextual_help = '<p>aide edition du type (taxonomie) </p>';
        }
        return $contextual_help;
    }
    add_action( 'contextual_help', 'lgib_vehicule_add_help_text', 10, 3);
    
    // ================================================= onglets aide personnalisés
    function lgib_vehicule_custom_help_tab()  {
        global $post_ID;
        $screen = get_current_screen();
    
        if ( isset($_GET['post_type']) )  {
          $post_type = $_GET['post_type'];
        }  else  {
          $post_type = get_post_type( $post_ID );
        }
    
        if ( $post_type == 'lgib_vehicule') {
            $screen->add_help_tab( array(
                'id' => 'lgib_tab1',
                'title' => 'onglet supplémentaire',
                'content' => '<h3>ici un onglet supplémentaire</h3>'
            ));
        }
    
        if (is_taxonomy('lgib_type'))  {
            $screen->add_help_tab( array(
                'id' => 'lgib_type_help',
                'title' => 'Aide sur le type',
                'content' => '<h3>choisissez un type dans la liste</h3>'
            ));
        }
    }
    add_action( 'admin_head', 'lgib_vehicule_custom_help_tab');
    
    // ========================================================================
    // ------------ taxonomie associé au  custom-post-type véhicule -----------
    // ========================================================================
    function lgib_vehicule_taxonomy()  {
      $args = array(
          'label'   =>  'type',
          'query_var' => true,
          'rewrite' =>  array('slug'=>'type'),
          'hierarchical' => true,
          'show_admin_column' => true,
          'sort' => true,
          'public' => true
      );
      register_taxonomy( 'lgib_type', 'lgib_vehicule', $args );
    }
    
    add_action('init', 'lgib_vehicule_taxonomy');
    
    // ========================================================================
    // ------ custom meta-boxes associé au  custom-post-type véhicule ---------
    // ========================================================================
    function lgib_vehicule_meta_box()  {
        add_meta_box(
            'lgib_vehicule_meta',
            'Détails du véhicule',
            'lgib_vehicule_meta_populate',
            'lgib_vehicule',
            'advanced',
            'default'
        );
    }
    
    // =================================  fonction de remplissage des champs
    function lgib_vehicule_meta_populate($post)  {
        wp_nonce_field( plugin_basename(__FILE__), 'lgib_custom_type_noncename' );
    
        $serie = get_post_meta( $post->ID, 'lgib_vehicule_serie', true );   ?>
        <p>
        <label for="lgib_vehicule_serie">Série: </label>
        <input type="text" class="all-options" name="lgib_vehicule_serie" id="lgib_vehicule_serie"
        value="<?php echo esc_attr( $serie );   ?>"  />
        <span class="description">Entrer la série modèle du véhicule</span>
        </p>
    <?php
    }
    
    add_action('add_meta_boxes', 'lgib_vehicule_meta_box');
    
    // =================================  fonction de sauvegarde des champs
    function lgib_vehicule_meta_save($post_id)  {
        if ( defined( 'DOING_AUTOSAVE' )  && DOING_AUTOSAVE )  {
            return $post_id;
        }
    
        if ( !isset( $_POST['lgib_custom_type_noncename'] ) || !wp_verify_nonce( $_POST['lgib_custom_type_noncename'], plugin_basename(__FILE__) ) ) {
            return $post_id;
        }
    
        global $post;
        $post_type = get_post_type_object($post->post_type);
    
        if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) {
            return $post_id;  echo '03'; die();
        }
        //echo '02'; die();
        $metadata['lgib_vehicule_serie'] = ( isset ($_POST['lgib_vehicule_serie'] ) ? $_POST['lgib_vehicule_serie'] : '' ); 
    
          foreach ( $metadata as $key=>$value ) {
    
            $current_value = get_post_meta( $post_id, $key, true);
            if ( $value && '' == $current_value )  {
                add_post_meta( $post_id, $key, $value, true);
            } else if ( $value && $value != $current_value )  {
                update_post_meta( $post_id, $key, $value);
            } else if ( '' == $value && $current_value )  {
                delete_post_meta($post_id, $key, $current_value );
            }
        }
    }
    
    add_action('save_post', 'lgib_vehicule_meta_save');
    ?>
Viewing 9 replies - 1 through 9 (of 9 total)