Create menus in Wordpress Dashboard

Asked

Viewed 325 times

2

I need to create custom menus for a Wordpress theme and I came to this function that works in parts, because the part of "TITLE" and fields of "TEXTS" or "SIDERBARS", can tell me where I’m going wrong?

// Function para novos menus
function theme_options_panel(){
   add_menu_page(
       'Theme page title', 
       'Artigos', 
       'manage_options', 
       'theme-options', 
       'wps_theme_func'
   );
}

add_action('admin_menu', 'theme_options_panel');

function wps_theme_func(){
    echo '<div class="wrap"><div id="icon-options-general" class="icon32"><br></div>
    <h2>Insira um artigo</h2></div>';
}

This is what happens:

Resultado

1 answer

2

The functions add_menu_page and add_submenu_page are just like that, if you want to fill out that question you will have to customize everything from the <h2>Insira um artigo</h2>.

But what you seek are Types of Custom Posts. The following code creates a TPP. Remarks:

  • the domain meu-tpp is used for translation, check the documentation Translating Wordpress. But if you want you can remove all functions __() and _x() leaving the strings clean.
  • also check the various parameters that can be used in register_post_type, especially in the array 'supports' => array( 'title', 'editor', etcetera ).
  • to further customize the TPP, we will use Custom Meta Boxes, which can be registered in the option register_meta_box_cb (disabled in the example below). See a example in the OS.
add_action( 'init', 'criar_artigos_sopt_9881' );

function criar_artigos_sopt_9881() 
{
    $labels = array(
        'name' => _x( 'Artigos', 'post type general name', 'meu-tpp' ),
        'singular_name' => _x( 'Artigo', 'post type singular name', 'meu-tpp' ),
        'add_new' => _x( 'Add New', 'artigo', 'meu-tpp' ),
        'add_new_item' => __( 'Add New Artigo', 'meu-tpp' ),
        'edit_item' => __( 'Edit Artigo', 'meu-tpp' ),
        'new_item' => __( 'New Artigo', 'meu-tpp' ),
        'all_items' => __( 'All Artigos', 'meu-tpp' ),
        'view_item' => __( 'View Artigo', 'meu-tpp' ),
        'search_items' => __( 'Search Artigos', 'meu-tpp' ),
        'not_found' =>  __( 'No artigos found', 'meu-tpp' ),
        'not_found_in_trash' => __( 'No artigos found in Trash', 'meu-tpp' ), 
        'parent_item_colon' => '',
        'menu_name' => __( 'Artigos', 'meu-tpp' )
    );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true, 
        'show_in_menu' => true, 
        'query_var' => true,
        'rewrite' => array( 'slug' => _x( 'artigo', 'URL slug', 'meu-tpp' ) ),
        'capability_type' => 'page',
        'has_archive' => true, 
        'hierarchical' => false,
        'menu_position' => null,
        'taxonomies' => array('category'),
        'supports' => array( 'title', 'editor', 'comments', 'custom-fields', 'thumbnail' ),
        //'register_meta_box_cb' => 'my_meta_boxes'
    );

    register_post_type( 'artigo', $args );
}

inserir a descrição da imagem aqui

  • Thank you, it worked perfect.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.