[Support request] Static page for custom post type archive

Home Forums Support [Support request] Static page for custom post type archive

Home Forums Support Static page for custom post type archive

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #2025477
    Hilton

    I have created a custom post type ‘videos’, but I don’t want to use archive-videos.php to list the videos. I need to use a static page to list my videos because I would like to add content using the content editor along with WP Show Posts plugin.

    I would like this structure:
    http://www.example.com/videos —> It is a static page
    http://www.example.com/videos/video-title —> it is single post type

    I am currently using this functions for custom post type:

    // REGISTER CUSTOM POST TYPES
    //===== MBF_Videos Custom Type ======//
    function custom_mbfvideo_type() {
        // Labels for Custom Post Type
        $labels = array(
            'name'                => _x( 'Videos', 'Post Type General Name', 'mbfpress-child' ),
            'singular_name'       => _x( 'Video', 'Post Type Singular Name', 'mbfpress-child' ),
            'menu_name'           => __( 'Videos', 'mbfpress-child' ),
            'parent_item_colon'   => __( 'Parent post', 'mbfpress-child' ),
            'all_items'           => __( 'Todos posts', 'mbfpress-child' ),
            'view_item'           => __( 'Ver post', 'mbfpress-child' ),
            'add_new_item'        => __( 'Adicionar novo item', 'mbfpress-child' ),
            'add_new'             => __( 'Adicionar novo', 'mbfpress-child' ),
            'edit_item'           => __( 'Editar', 'mbfpress-child' ),
            'update_item'         => __( 'Atualizar', 'mbfpress-child' ),
            'search_items'        => __( 'Buscar', 'mbfpress-child' ),
            'not_found'           => __( 'Não encontrado', 'mbfpress-child' ),
            'not_found_in_trash'  => __( 'Não encontrado na lixeira', 'mbfpress-child' ),
        );
         
        // Customize option for Custom Post Type  
        $args = array(
            'description'         => __( 'Videos do site Mysite', 'mbfpress-child' ),
            'labels'              => $labels,
            'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
            'taxonomies'          => array( 'category', 'post_tag' ),
            'public'              => true,
            'show_ui'             => true,
            'show_in_menu'        => true,
            'show_in_nav_menus'   => true,
            'show_in_admin_bar'   => true,
    	'show_in_rest'	      => true, // To use Gutenberg editor.
            'menu_position'       => 5,
            'can_export'          => true,
            'has_archive'         => true,
            'exclude_from_search' => false,
            'publicly_queryable'  => true,
    	'menu_icon'           => 'dashicons-admin-site-alt2',
            'capability_type'     => 'post',
        );
        // Registering your Custom Post Type
        register_post_type( 'video', $args );
    }
     
    add_action( 'init', 'custom_mbfvideo_type', 0 );
    #2026108
    David
    Staff
    Customer Support

    Hi there,

    i found this stack exchange answer which looks like it does what you require.

    https://wordpress.stackexchange.com/a/165474

    #2026151
    Hilton

    Hi David,

    From the following comment it sounds like this is a workaround. Let me ask it in a different way… if I wanted one archive page to have more flexibility for editing, where if possible within the admin I would edit it as if it were a page, what would be the best solution for that?

    Thanks

    #2026162
    David
    Staff
    Customer Support

    You can’t edit an Archive page in WP.
    The Answer that i linked to provides the method to use a ‘static’ page in in place of the term archive, whilst keeping the permalink structure. ( The following/last answer you can ignore – it isn’t connected to accepted answer )

    #2026955
    Hilton

    Hi David,

    My site’s permalink structure is //mysite.com/post-example/. So using the function you suggested didn’t work for me because I don’t want the domain //mysite.com/videos/%type%/post-title/ but just //mysite.com/videos/post-title/.

    With this function below, you can see that I got more or less what I wanted ( https://bit.ly/3p7oSHJ ). The problem was due to the url //mysite.com/videos/ ( https://bit.ly/3lfA0B3 ) that I would like to know how I could customize it showing a list of videos, and possibly using WP Show Posts on it.

    An alternative I thought would be to disable the_loop on it, and use “Elements” to add a custom hook after (or before, whatever) the main content, but I don’t know if it is the best one.

    function custom_mdvideo_type() {
        // Labels for Custom Post Type
        $labels = array(
            'name'                => _x( 'Videos', 'Post Type General Name', 'mbfpress-child' ),
            'singular_name'       => _x( 'Video', 'Post Type Singular Name', 'mbfpress-child' ),
            'menu_name'           => __( 'Videos', 'mbfpress-child' ),
            'parent_item_colon'   => __( 'Parent post', 'mbfpress-child' ),
            'all_items'           => __( 'Todos posts', 'mbfpress-child' ),
            'view_item'           => __( 'Ver post', 'mbfpress-child' ),
            'add_new_item'        => __( 'Adicionar novo item', 'mbfpress-child' ),
            'add_new'             => __( 'Adicionar novo', 'mbfpress-child' ),
            'edit_item'           => __( 'Editar', 'mbfpress-child' ),
            'update_item'         => __( 'Atualizar', 'mbfpress-child' ),
            'search_items'        => __( 'Buscar', 'mbfpress-child' ),
            'not_found'           => __( 'Não encontrado', 'mbfpress-child' ),
            'not_found_in_trash'  => __( 'Não encontrado na lixeira', 'mbfpress-child' ),
        );
         
        // Customize option for Custom Post Type  
        $args = array(
            'label'               => __( 'Videos', 'mbfpress-child' ),
            'description'         => __( 'Videos from my website', 'mbfpress-child' ),
            'labels'              => $labels,
            // Custom Post Type supports features in the Post Editor
            'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
            // You can associate this Custom Post Type with sa taxonomy or custom taxonomy. 
            'taxonomies'          => array( 'category', 'post_tag' ),
            'hierarchical'        => false,
            'public'              => true,
            'show_ui'             => true,
            'show_in_menu'        => true,
            'show_in_nav_menus'   => true,
            'show_in_admin_bar'   => true,
    	'show_in_rest'	      => true, // To use Gutenberg editor.
            'menu_position'       => 25,
            'can_export'          => true,
            'has_archive'         => true,
            'exclude_from_search' => false,
            'publicly_queryable'  => true,
    	'rewrite' 	      => array('slug' => 'videos'),
    	'menu_icon'           => 'dashicons-admin-site-alt2',
            'capability_type'     => 'post',
        );
        // Registering your Custom Post Type
        register_post_type( 'videos', $args );
    }
     
    add_action( 'init', 'custom_mdvideo_type', 0 );
    #2027365
    David
    Staff
    Customer Support

    Not sure if its necessary to disable the loop – however theres a method provided here ( albeit for search page the same applies for any template ):

    https://generatepress.com/forums/topic/google-site-searchcustom-search-implementation/page/2/#post-1656373

    As you already have hooks within the theme templates:

    https://docs.generatepress.com/article/hooks-visual-guide/

    You could simply hook in your ‘custom’ content using hooks or Elements …

    #2028004
    Hilton

    Thanks David!

    #2028005
    Hilton

    It worked 😉

    #2028767
    David
    Staff
    Customer Support
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.