Advertisement
Guest User

Functions wordpress

a guest
Oct 4th, 2011
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.11 KB | None | 0 0
  1.  
  2. add_action('init', 'post_type_producten');
  3. add_action( 'init', 'create_producten_taxonomies', 0 );
  4.  
  5. add_filter('post_type', 'projecten_permalinks', 1, 3);
  6. add_filter('post_type_link', 'projecten_permalinks', 1, 3);
  7.  
  8. // ## PROJECTEN CUSTOM POST TYPE
  9. function post_type_producten() {
  10.     $labels = array(
  11.         'name'                              => _x('Producten', 'post type general name'),
  12.         'singular_name'             => _x('Producten', 'post type singular name'),
  13.         'add_new'                       => _x('Nieuw product', 'producten'),
  14.         'add_new_item'              => __('Nieuw product toevoegen'),
  15.         'edit_item'                     => __('Product bewerken'),
  16.         'new_item'                      => __('Nieuw Product'),
  17.         'view_item'                     => __('Bekijk Product'),
  18.         'search_items'              => __('Zoek Producten'),
  19.         'not_found'                     =>  __('Geen producten gevonden'),
  20.         'not_found_in_trash'    => __('Geen producten in de prullenbak'),
  21.         'parent_item_colon'     => '');
  22.                        
  23.     $args = array(
  24.         'label'                     => __('Projecten'),
  25.         'labels'                    => $labels,
  26.         'public'                    => true,
  27.         'hierarchical'      => false,
  28.         'show_ui'               => true,
  29.         'supports'              => array('title','editor','thumbnail','revisions'),
  30.         'has_archive'       => true,
  31.         'menu_position'     => 5,
  32.         'taxonomies'            => array('productCat'),
  33.         'rewrite'               => array(
  34.             'slug'              => 'producten/%productCat%',
  35.             'with_front'    => true,
  36.             'hierarchical' => true
  37.         )
  38.     );
  39.     register_post_type('producten', $args);
  40.     flush_rewrite_rules();
  41. }
  42.  
  43.  
  44. //taxonomies registreren
  45. function create_producten_taxonomies()
  46. {
  47.   // productCat
  48.   $labels = array(
  49.     'name' => _x( 'Product categorieën', 'taxonomy general name' ),
  50.     'singular_name' => _x( 'Product categorieën', 'taxonomy singular name' ),
  51.     'search_items' =>  __( 'Zoek Product categorieën' ),
  52.     'all_items' => __( 'Alle categorieën' ),
  53.     'parent_item' => __( 'Bovenliggende categorie' ),
  54.     'parent_item_colon' => __( 'Hoofd categorie:' ),
  55.     'edit_item' => __( 'Wijzig categorie' ),
  56.     'update_item' => __( 'Update categorie' ),
  57.     'add_new_item' => __( 'Nieuwe categorie' ),
  58.     'new_item_name' => __( 'Nieuwe categorie naam' ),
  59.     'menu_name' => __( 'Categorieën' ),
  60.   );    
  61.  
  62.   register_taxonomy('productCat',array('producten'), array(
  63.     'hierarchical'  => true,
  64.     'labels'                => $labels,
  65.     'show_ui'           => true,
  66.     'query_var'         => true,
  67.     'rewrite'           => array( 'slug'                    => 'producten/%productCat%',
  68.                                                         'hierarchical'  => true,
  69.                                                         'with_front'        => false  )
  70.   ));
  71.   flush_rewrite_rules();
  72. }
  73.  
  74.  
  75. // Permalinks projecten
  76.  
  77. function projecten_permalinks( $post_link, $id = 0, $leavename = FALSE ) {
  78.     if ( strpos('%productCat%', $post_link) < 0 ) {
  79.         return $post_link;
  80.     }
  81.     $post = get_post($id);
  82.     if ( !is_object($post) || $post->post_type != 'producten' ) {
  83.         return $post_link;
  84.     }
  85.     $terms = wp_get_object_terms($post->ID, 'productCat');
  86.     //print_r($terms);
  87.     if ( !$terms ) {
  88.         return str_replace('%productCat%', '', $post_link);
  89.     }
  90.     $perm = $terms[0]->slug;
  91.     if(!empty($terms[1]->slug)) {
  92.         $perm = $terms[0]->slug.'/'.$terms[1]->slug;
  93.     }
  94.    
  95.    
  96.     return str_replace('%productCat%', $perm, $post_link);
  97. }
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement