1. Home
  2. ReHub Theme
  3. Advanced tips and customizations
  4. Adding custom Post layouts

Adding custom Post layouts

One of big advantages of our theme is that Rehub has many ready Post layouts which can change your regular post view to e-commerce style, price comparison style, review style and much more. Read about this

You can also add own custom post layouts with next steps.

First of all, register your post layout in select box. For example, you want to register layout with name “My custom post layout” and key “custom_one”.

Use next code in functions.php

add_filter('rehub_post_layout_array', 'mycustom_layout_for_rehub');
function mycustom_layout_for_rehub() {
$custom_post_layout = array(
array(
'value' => 'default',
'label' => __('Simple', 'rehub_framework'),
),
array(
'value' => 'meta_outside',
'label' => __('Title is outside content', 'rehub_framework'),
),
array(
'value' => 'meta_center',
'label' => __('Center aligned (Rething style)', 'rehub_framework'),
), 
array(
'value' => 'meta_compact',
'label' => __('Compact (Recash style)', 'rehub_framework'),
),
array(
'value' => 'meta_compact_dir',
'label' => __('Compact (Redirect style)', 'rehub_framework'),
), 
array(
'value' => 'corner_offer',
'label' => __('Button in corner (Repick style)', 'rehub_framework'),
), 
array(
'value' => 'meta_in_image',
'label' => __('Title Inside image', 'rehub_framework'),
), 
array(
'value' => 'meta_in_imagefull',
'label' => __('Title Inside full image', 'rehub_framework'),
),
array(
'value' => 'big_post_offer',
'label' => __('Big post offer block in top', 'rehub_framework'),
), 
array(
'value' => 'offer_and_review',
'label' => __('Offer and review score', 'rehub_framework'),
), 
array(
'value' => 'meta_ce_compare',
'label' => __('Price comparison (Content Egg or Multioffer)', 'rehub_framework'),
),
array(
'value' => 'custom_one',
'label' => __('My custom post layout', 'rehub_framework'),
),
);
return $custom_post_layout;
}

As you see, you have all layouts in array (so, you can delete some if you don’t need them) and we add our layout in end. This is for global post option. Now you need to customize also single post option. code is next

add_filter('rehub_post_layouts_array', 'mysingle_layout_for_rehub');
function mysingle_layout_for_rehub() {
    $postlayout = array(
	'default'=> esc_html__('Simple', 'rehub-framework'),
	'default_full_opt'=> esc_html__('Optimized Full width', 'rehub-framework'),
	'meta_outside'=> esc_html__('Title is outside content', 'rehub-framework'),
	'guten_auto'=> esc_html__('Gutenberg Auto Contents', 'rehub-framework'),
	'default_text_opt'=> esc_html__('Optimized for reading with sidebar', 'rehub-framework'),
	'video_block'=> esc_html__('Video Block', 'rehub-framework'),
	'meta_center'=> esc_html__('Center aligned (Rething style)', 'rehub-framework'),
	'meta_compact'=> esc_html__('Compact (Button Block Under Title)', 'rehub-framework'),
	'meta_compact_dir'=> esc_html__('Compact (Button Block Before Title)', 'rehub-framework'),
	'corner_offer'=> esc_html__('Button in corner (Repick style)', 'rehub-framework'),
	'meta_in_image'=> esc_html__('Title Inside image', 'rehub-framework'),
	'meta_in_imagefull'=> esc_html__('Title Inside full image', 'rehub-framework'),
	'big_post_offer'=> esc_html__('Big post offer block in top', 'rehub-framework'),
	'custom_one'=> esc_html__('My custom post layout', 'rehub-framework')
    );
    return $postlayout;
}

Here we do the same job, we can remove unwanted layouts and add our custom_one

Now, you need to customize single page template to show your layout

Copy file single.php from main theme and insert it in your child theme or grandchild plugin.

Find lines

<?php else:?>
    <?php include(rh_locate_template('inc/post_layout/single-default.php')); ?>

insert before this line

<?php elseif($rh_post_layout_style == 'custom_one') : ?>
    <?php include(rh_locate_template('inc/post_layout/custom_one.php')); ?>

Now, last step, you need to create template for your layout. Copy one of templates from folder inc/post_layout. Rename it to custom_one.php and place in folder inc/post_layout (you must create it) inside child theme or grand child plugin.

Here details about using child themes and grandchild plugin