📜 ⬆️ ⬇️

How to use your content type

Portfolio There are two types of content in Wordpress: Posts and Pages.
These types contain fields such as title, description, categories / tags.
Additional description can be created using Custom Fields.

Wordpress 3.0 has the ability to create your own content type.

The idea is to create a new type of content, such as a portfolio (name, description, website address, release date, customer name, technologies used) that would not be displayed along with the posts and would have a different idea.
Wordpress

Register your content type


Go to the folder of the current theme and create the file “functions.php” if it is not already there.
Here we can write event hooks and add necessary actions.
')
  1. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  2. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  3. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  4. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  5. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  6. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  7. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  8. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  9. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  10. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  11. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  12. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  13. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  14. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  15. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  16. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  17. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  18. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  19. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  20. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  21. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  22. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  23. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  24. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  25. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  26. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  27. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  28. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  29. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  30. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  31. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }
  32. // add_action ( 'init' , 'portfolio_init' ) ; function portfolio_init ( ) { // $args = array ( 'label' => __ ( 'Portfolio' ) , 'labels' => array ( 'edit_item' => __ ( 'Edit Work' ) , 'add_new_item' => __ ( 'Add New Work' ) , 'view_item' => __ ( 'View Work' ) , ) , 'singular_label' => __ ( 'Work' ) , 'public' => true , 'show_ui' => true , // ? '_builtin' => false , // '_edit_link' => 'post.php?post=%d' , 'capability_type' => 'post' , 'hierarchical' => false , 'rewrite' => array ( "slug" => "medewerkers" ) , // 'supports' => array ( 'title' , 'editor' , 'thumbnail' ) ) ; // register_post_type ( 'portfolio' , $args ) ; // - // ( ) register_taxonomy ( 'mtype' , 'portfolio' , array ( 'hierarchical' => false , 'label' => __ ( 'Technologies' ) , 'singular_label' => __ ( 'Technology' ) , 'query_var' => 'mtype' ) ) ; }


Change the editing interface


  1. // add a hook to admin initialization
  2. add_action ( "admin_init" , 'portfolio_admin_init' ) ;
  3. function portfolio_admin_init ( ) {
  4. // add additional block
  5. add_meta_box ( "portfolio-meta" , "Details" , portfolio_options , 'portfolio' , 'normal' , 'low' ) ;
  6. }
  7. // describe the block
  8. function portfolio_options ( ) {
  9. global $ post ;
  10. // Use hidden field for
  11. echo '<input type = "hidden" name = "portfolio_noncename" id = "portfolio_noncename" value = "' .
  12. wp_create_nonce ( 'portfolio' ) . '"/>' ;
  13. // our fields
  14. $ my_fields = array ( 'web' => '' , 'customer' => '' , 'web' => '' , 'date' => '' ) ;
  15. foreach ( $ my_fields as $ key => $ value ) {
  16. $ my_fields [ $ key ] = get_post_meta ( $ post -> ID , 'portfolio-' . $ key , true ) ;
  17. }
  18. echo '<strong> Web site </ strong> <br/> <br/> <input name = "portfolio-web" size = "60" value = "' . $ my_fields [ 'web' ] . '" /> <br/> <br/> ' . " \ n " ;
  19. echo '<strong> Customer </ strong> <br/> <br/> <input name = "portfolio-customer" size = "60" value = "' . $ my_fields [ 'customer' ] . '" /> < br /> <br/> ' . " \ n " ;
  20. echo '<strong> Release date </ strong> <br/> <br/> <input name = "portfolio-date" size = "60" value = "' . $ my_fields [ 'date' ] . " "/> <br/> <br/> ' . " \ n " ;
  21. }


example


Preservation


  1. // add a hook to save the post
  2. add_action ( 'save_post' , 'portfolio_save' , 1 , 2 ) ;
  3. function portfolio_save ( ) {
  4. global $ post ;
  5. $ post_id = $ post -> ID ;
  6. // determine that the data came with our form and correct authorization
  7. // because save_post can be called in other cases
  8. if ( ! wp_verify_nonce ( $ _POST [ 'portfolio_noncename' ] , 'portfolio' ) ) return $ post_id ;
  9. // if it is autosave, then the form is not saved and we do nothing
  10. if ( defined ( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $ post_id ;
  11. // flag to define a custom data type, it is not particularly needed here, but it does not hurt
  12. $ post_flag = 'x' ;
  13. if ( $ post -> post_type == "portfolio" ) {
  14. $ my_fields = array ( 'web' => '' , 'customer' => '' , 'web' => '' , 'date' => '' ) ;
  15. $ post_flag = 'portfolio' ;
  16. }
  17. if ( $ post_flag ! = 'x' ) {
  18. // this is our content type.
  19. // go through all the fields
  20. foreach ( $ my_fields as $ k => $ v )
  21. {
  22. $ key = 'portfolio-' . $ post_flag . '-' . $ k ;
  23. $ value = @ $ _POST [ $ key ] ;
  24. if ( empty ( $ value ) )
  25. {
  26. delete_post_meta ( $ post_id , $ key ) ;
  27. continue ;
  28. }
  29. // if the value is a string, then it must be unique
  30. if ( ! is_array ( $ value ) )
  31. {
  32. // update meta information
  33. if ( ! update_post_meta ( $ post_id , $ key , $ value ) )
  34. {
  35. // or add
  36. add_post_meta ( $ post_id , $ key , $ value ) ;
  37. }
  38. }
  39. else
  40. {
  41. // if we are here, we need to delete the keys
  42. delete_post_meta ( $ post_id , $ key ) ;
  43. // go through the array and add new values ​​to the meta-information as different cells with the same name
  44. foreach ( $ value as $ entry )
  45. add_post_meta ( $ post_id , $ key , $ entry ) ;
  46. }
  47. }
  48. }
  49. }


Change the pivot table in the admin panel


  1. add_action ( "manage_posts_custom_column" , "portfolio_custom_columns" ) ;
  2. add_filter ( "manage_edit-portfolio_columns" , "portfolio_columns" ) ;
  3. // column names
  4. function portfolio_columns ( $ columns )
  5. {
  6. $ columns = array (
  7. "cb" => "<input type = \" checkbox \ " />" ,
  8. "title" => "Name" ,
  9. "web" => "Web Site" ,
  10. "customer" => "Customer" ,
  11. "date" => "Release date"
  12. ) ;
  13. return $ columns ;
  14. }
  15. // column contents
  16. function portfolio_custom_columns ( $ column )
  17. {
  18. global $ post ;
  19. if ( "ID" == $ column ) echo $ post -> ID ;
  20. elseif ( "title" == $ column ) echo $ post -> post_title ;
  21. elseif ( "web" == $ column ) {
  22. $ ourl = get_post_meta ( $ post -> ID , 'portfolio-web' , true ) ;
  23. echo '<a href="'. $ourl.'" target="_blank">' . $ ourl . '</a>' ;
  24. }
  25. elseif ( "customer" == $ column ) {
  26. $ ocustomer = get_post_meta ( $ post -> ID , 'portfolio-customer' , true ) ;
  27. echo $ ocustomer . '</a>' ;
  28. }
  29. elseif ( "date" == $ column ) {
  30. $ odate = get_post_meta ( $ post -> ID , 'portfolio-date' , true ) ;
  31. echo $ odate '</a>' ;
  32. }
  33. }


Conclusion


Next time I will write about how to style the output of such content in the subject.

Source: https://habr.com/ru/post/97247/


All Articles