简体   繁体   English

添加到导航自定义类型帖子WordPress

[英]Add to nav custom type posts WordPress

I am trying to create a menu consisting of posts custom type, but they are not present in the selection menu. 我正在尝试创建一个由帖子自定义类型组成的菜单,但是选择菜单中不存在它们。 Can be I forgot what the properties on custom type? 我可以忘记自定义类型的哪些属性吗?

My code: 我的代码:

//Создание страницы новостроек

add_action( 'init', 'register_house_page' ); // Использовать функцию только внутри хука init

function register_house_page() {
    $labels = array(
        'name' => 'Новостройки КРЕО',
        'singular_name' => 'Новостройки', // админ панель Добавить->Функцию
        'add_new' => 'Добавить новостройку',
        'add_new_item' => 'Добавить новую новостройку', // заголовок тега <title>
        'edit_item' => 'Редактировать новостройку',
        'new_item' => 'Новая новостройка',
        'all_items' => 'Все новостройки',
        'view_item' => 'Просмотр новостройки на сайте',
        'search_items' => 'Искать новостройку',
        'not_found' =>  'Новостроек не найдено.',
        'not_found_in_trash' => 'В корзине нет новостроек.',
        'menu_name' => 'Новостройки КРЕО' // ссылка в меню в админке
    );
    $args = array(
        'labels' => $labels,
        'public' => true,
        'show_ui' => true, // показывать интерфейс в админке
        'has_archive' => true, 
        'menu_icon' => 'dashicons-admin-multisite', // иконка в меню
        'menu_position' => 21, // порядок в меню
        'supports' => array( 'title', 'editor'),
        'taxonomies'          => array(),
        'has_archive'         => false,
        'rewrite'             => true,
        'query_var'           => true,
        'show_in_nav_menus'   => true, // зависит от public
    );
    register_post_type('kreo_house', $args);
}

I have 4 posts image1 我有4个帖子image1

but cant see in menu 但在菜单中看不到

image2 image2

I'm not sure if when you say that you want to create a menu related with the custom post types are you talking into the dashboard or directly in you page but based in you code, I'm assuming that you are trying to show your custom post type in the dashboard for that you could use something similar to this 我不确定当您说要创建与自定义帖子类型相关的菜单时,是在仪表板中还是直接在您的页面中,但是基于您的代码,我是假设您正在尝试显示自己的仪表板中的自定义帖子类型,您可以使用与此类似的内容

add_action( 'init', 'create_post_type_new_post' );
function create_post_type_new_post() {
    register_post_type( 'new-post',
        array(
            'labels' => array(
                'name' => __( 'Новостройки КРЕО' ),
                'singular_name' => __( 'Новостройки КРЕО' )
                //more options here
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'new-post'),
            'supports' => array('title', 'editor'),
            'menu_icon'   => 'dashicons-admin-multisite',
            //more options here
        )
    );
}

I added normally the code mentioned above in a separate file and imported it into the functions.php file 我通常将上述代码添加到一个单独的文件中,并将其导入到functions.php文件中

   $file = TEMPLATEPATH."/inc/your-name-file.php";
   if(file_exists($file)){
     require_once($file);
   }

I hope this could help you! 希望对您有所帮助!

UPDATE: If you want to show your custom post type in the menu or your site, you need to create a custom link in the menu section, linked to the archive 更新:如果要在菜单或站点中显示自定义帖子类型,则需要在菜单部分中创建一个自定义链接,链接到存档

If archives are enabled for a custom post type, then you can display them on your website.The URL of your custom post type archive page should be like this: 如果为自定义帖子类型启用了存档,则可以将其显示在您的网站上。自定义帖子类型存档页面的URL应该如下所示:

http://yoursite.com/post-type-slug/ http://yoursite.com/post-type-slug/

You can place a link for the archives for each custom post type into your navigation menus. 您可以将每种自定义帖子类型的存档链接放入导航菜单。

You need to visit Appearance > Menus page. 您需要访问外观>菜单页面。 You need to click on the name of your custom post You will see an option for your post type archives. 您需要单击自定义帖子的名称。您将看到一个帖子类型档案的选项。

If after this you continue without see your menu option, try the follow: 如果在此之后继续操作而看不到菜单选项,请尝试以下操作:

Enable debug option adding to your wp-config.php and verify if some error is appearing 启用添加到wp-config.php的调试选项,并验证是否出现一些错误

define('WP_DEBUG', true);

Sometimes the custom post type name's lenght causes errors 有时自定义帖子类型名称的长度会导致错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM