Load individual blog category into page

Hi,

I have a bit of a strange one...

My customer has me designing her site in such a way that it is split into two parts. Weddings and Family & Children. She wants to have it look like she has two separate blogs - Weddings Blog and Family & Children Blog. I had originally intended to use categories to achieve this and just link directly to the right category, but as she has two different menus that would need to appear on each category I'm not sure this would work.

I.e The weddings blog category display would need to show the weddings menu (which I have set up as a layout) and the Family & Childrens blog category would need to show the F&C menu which is also set up as a layout.

So I thought to avoid this maybe I could use a normal single page layout and use the data element to call the category into the space that I wanted it to appear, but from what I can see, that doesn't seem possible. Is there some sort of code that can do this?

Hope my problem makes sense, if you need me to clarify let me know!
Stacey

  • James Morris

    Hello Stacey,

    I hope you are well today.

    Actually, reading through your description, this sounds like Custom Post Types would be a better. This would allow you to create a new Archive template for that specific Post Type. You could then associate a region that is only to be displayed on pages of that type, such as your menus. This would overcome the issue of having 2 menus and 2 blogs. Also, it would give you two sections in the backend for the specific post types, thus making organization much easier.

    The simplest form of registering a Custom Post Type is to add something like the following to a mu-plugin in /wp-content/mu-plugins/. I've attached a sample file:

    <?php
    function wedding_custom_post_type() {
        $args = array(
          'public' => true,
          'label'  => 'Weddings'
        );
        register_post_type( 'wedding', $args );
    }
    add_action( 'init', 'wedding_custom_post_type' );
    
    function family_custom_post_type() {
        $args = array(
          'public' => true,
          'label'  => 'Family & Children'
        );
        register_post_type( 'family', $args );
    }
    add_action( 'init', 'family_custom_post_type' );

    Of course, this is a very limited example. You'll want to customize this further for the greatest functionality. See: https://codex.wordpress.org/Function_Reference/register_post_type

    Note: Don't forget to resave your permalinks after registering your Custom Post Types!

    I hope this clarifies a bit. Let us know if you have any further questions. We'll be happy to help! :slight_smile:

    Best regards,

    James Morris

  • James Morris

    Hello Stacey,

    mu-plugins are files that are located at /wp-content/mu-plugins and are what's called "Must Use" plugins. They cannot be deactivated. They are independent of themes. And they are the preferred way to add global features to your site, such as Custom Post Types.

    See: https://codex.wordpress.org/Must_Use_Plugins

    By default, most WordPress installations do not have a mu-plugins folder under wp-content. You can easily create this folder via your FTP client or hosting control panel file manager, though. Once you have done that, you can simply download the .zip file I have provided above, extract the .php file that is inside of it, and upload that .php file to your server inside the mu-plugins folder.

    The Custom Post Types I've defined are basic. They have just enough information defined to create posts. However, if you want taxonomy available to those post types (such as category and tags) then some minor changes would need to be made to the code.

    If you want, you can just replace the code I provided in the file with the following. This will give you full featured posts, like the WordPress default, but will be custom to the content you want to display.

    <?php
    function wedding_custom_post_type() {
    	$labels = array(
    		'name'               => _x( 'Weddings', 'post type general name' ),
    		'singular_name'      => _x( 'Wedding', 'post type singular name' ),
    		'menu_name'          => _x( 'Weddings', 'admin menu' ),
    		'name_admin_bar'     => _x( 'Wedding', 'add new on admin bar' ),
    		'add_new'            => _x( 'Add New', 'Wedding' ),
    		'add_new_item'       => __( 'Add New Wedding' ),
    		'new_item'           => __( 'New Wedding' ),
    		'edit_item'          => __( 'Edit Wedding' ),
    		'view_item'          => __( 'View Wedding' ),
    		'all_items'          => __( 'All Weddings' ),
    		'search_items'       => __( 'Search Weddings' ),
    		'parent_item_colon'  => __( 'Parent Weddings:' ),
    		'not_found'          => __( 'No Weddings found.' ),
    		'not_found_in_trash' => __( 'No Weddings found in Trash.' )
    	);
    
    	$args = array(
    		'labels'             => $labels,
    		'public'             => true,
    		'publicly_queryable' => true,
    		'show_ui'            => true,
    		'show_in_menu'       => true,
    		'query_var'          => true,
    		'has_archive'        => true,
    		'hierarchical'       => false,
    		'menu_position'      => 5,
    		'taxonomies'		 => array( 'category', 'post_tag' ),
    		'rewrite'            => array( 'slug' => 'wedding' ),
    		'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments',  'revisions')
    	);
        register_post_type( 'wedding', $args );
    }
    add_action( 'init', 'wedding_custom_post_type' );
    
    function family_custom_post_type() {
    	$labels = array(
    	'name'               => _x( 'Family & Childrens', 'post type general name' ),
    	'singular_name'      => _x( 'Family & Children', 'post type singular name' ),
    	'menu_name'          => _x( 'Family & Childrens', 'admin menu' ),
    	'name_admin_bar'     => _x( 'Family & Children', 'add new on admin bar' ),
    	'add_new'            => _x( 'Add New', 'Family & Children' ),
    	'add_new_item'       => __( 'Add New Family & Children' ),
    	'new_item'           => __( 'New Family & Children' ),
    	'edit_item'          => __( 'Edit Family & Children' ),
    	'view_item'          => __( 'View Family & Children' ),
    	'all_items'          => __( 'All Family & Childrens' ),
    	'search_items'       => __( 'Search Family & Childrens' ),
    	'parent_item_colon'  => __( 'Parent Family & Childrens:' ),
    	'not_found'          => __( 'No Family & Childrens found.' ),
    	'not_found_in_trash' => __( 'No Family & Childrens found in Trash.' )
    	);
    
    	$args = array(
    		'labels'             => $labels,
    		'public'             => true,
    		'publicly_queryable' => true,
    		'show_ui'            => true,
    		'show_in_menu'       => true,
    		'query_var'          => true,
    		'has_archive'        => true,
    		'hierarchical'       => false,
    		'menu_position'      => 5,
    		'taxonomies'		 => array( 'category', 'post_tag' ),
    		'rewrite'            => array( 'slug' => 'family' ),
    		'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments',  'revisions')
    	);
        register_post_type( 'family', $args );
    }
    add_action( 'init', 'family_custom_post_type' );

    The advantage of doing it this way is you basically are running multiple blogs since each post type is isolated from the others.

    You should be able to copy and paste the code I've provided here and have fully functional post types.

    If you have any further questions, let us know. We'll be happy to help! :slight_smile:

    Best regards,

    James Morris

  • Stacey

    Hello!

    Sorry for the delay coming back to this.

    I've done as instructed above, and now have three different blogs on the site Family, weddings and the original 'posts' section, however I'm having trouble finding how to display all the family and childrens posts on a single page (i.e the blog homepage which then links to each individual blog post) - I've tried viewing what appears to be the blog type page (http://tessaclements.co.uk.gridhosted.co.uk/family/) but nothing comes up... and if I try and insert the blogs using the data section in the draggable elements, just the original post appears.

    Sorry if I'm being totally dim here!

    Basically, what I'm trying to acheive is one page with a list of all the family and children blog posts on, and another page with a list of all the wedding blogs on. Like this page: http://www.saraheverettphotography.co.uk/blog/

    Is that doable? If so, what am I doing wrong :S

    Thank you, Stacey

  • Luís

    Hi Stacey ,

    Hope you're doing well today!

    If I understood well, after create the page, you can use the "Posts" elements to display the posts list of your custom post type. You will need to edit the element settings and select "Post(s) by Taxonomy". Please check this video:

    https://www.screencast.com/t/GXOEYkqLE

    If I am missing something or this is not working for you, can you give us access to your admin panel, so we can investigate further?

    If you don't already know, please, follow the link below, to see how enable the staff login:

    http://premium.wpmudev.org/manuals/wpmu-dev-dashboard-enabling-staff-login/

    When you enable this option, please post again!

    Cheers, Luís

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.