Home Forums WoodMart support forum Issue with create_post_type

Issue with create_post_type

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #239518

    dima9891
    Participant

    I added simple post type in functions.php in child theme.
    Overall everything works great, but page title on this pages specifically doesn’t display. I mean title in the top of the page, just under the header. It displays everywhere else on the site, on every other page.

    Standard blog page (with title) – http://www.flora-center.ru/news/
    Custom page (no title) – http://www.flora-center.ru/poleznyie-stati/

    here is the code I added:

    add_action( 'init', 'create_post_type' );
    function create_post_type() {
    register_post_type( 'poleznyie-stati',
             array(
                    'labels' => array(
                    'name' => __( 'Статьи' ),
                    'singular_name' => __( 'Статья' ),
                    'has_archive' => true,
                    'add_new' => 'Добавить статью',
                    'not_found' => 'Ничего не найдено',
                    'not_found_in_trash' => 'В корзине статей не найдено'
                    ),
                    'public' => true,
                    'has_archive' => true,
                    'menu_position' => 5,
                    'supports' => array(
                        'title',
                        'editor',
                        'author',
                        'thumbnail',
                        'page-attributes',
                        'post-formats'
                    ),
                   'taxonomies' => array('category')
               ));
    }
    #239735

    Artem Temos
    Keymaster

    Hello,

    You can add it with additional code customization only. Edit the file woodmart/inc/template-tags.php and replace the following line

    if ( is_singular( 'page' ) && ( ! $page_for_posts || ! is_page( $page_for_posts ) ) ) :

    with this one

    if ( is_singular( 'page' ) && ( ! $page_for_posts || ! is_page( $page_for_posts ) ) || is_post_type_archive( 'poleznyie-stati' ) || is_singular( 'poleznyie-stati' ) ) :

    also, add the following snippet https://prnt.sc/vf5be1

    if ( is_post_type_archive( 'poleznyie-stati' ) ) {
        $title = 'Статьи';
    }

    Regards

    #239746

    dima9891
    Participant

    Thank you! that was usefull.
    I’ll just mention that if you don’t want to modify main theme files (to keep updates) – you should copy all page title function from woodmart/inc/template-tags.php to woodmart-child/funtions.php

    #239903

    Artem Temos
    Keymaster

    Yes, you can copy the whole function to the child theme to prevent loosing changes with future updates.

Viewing 4 posts - 1 through 4 (of 4 total)