The7 theme comes with dedicated meta boxes like Sidebar options, footer options, page header options etc for pages, posts and portfolios. But these options will not be available if you add a new custom post type or post types from other plugins, however, it can be added easily as below
Assume ‘cp_test’ is your custom post type, adding the following code in your child theme functions.php will add The7 sidebar, footer, fancy header and slideshow metaboxes to cp_test post type.
function add_dt_metaboxes_custom( $pages ) { $pages[] = 'cp_test'; $pages[] = 'cp_books'; // add each post type in new line return $pages; } add_filter( 'presscore_pages_with_basic_meta_boxes', 'add_dt_metaboxes_custom' );
If you are using custom template for post types, will need to add define few configs and call hooks to display these options in front end.
$config = Presscore_Config::get_instance(); $config->base_init(); get_header(); //and hooks like do_action( 'presscore_before_loop' ); do_action( 'presscore_after_loop' ); do_action('presscore_after_content');
Plase refer to ../dt-the7/single.php, archive.php for better understanding of these hooks. You can also try to duplicate the same files and make necessary changes for custom post type.
Programmatically controlling sidebar
If you don’t want to add The7 meta boxes to your custom post type, but only want to control the default sidebar settings (default to right)
add_action( 'get_header', 'cp_sidebar_filter', 10 ); function cp_sidebar_filter() { $config = Presscore_Config::get_instance(); if( 'cp_test' == get_post_type() ) { $config->set( 'sidebar_position', 'left' ); $config->set( 'sidebar_widgetarea_id', 'sidebar_1' ); $config->set( 'footer_show', '1' ); $config->set( 'footer_widgetarea_id', 'sidebar_2' ); } }
To disbale sidebar use config value disabled.
$config->set( 'sidebar_position', 'disabled' );
Your tips/explanation are super clear. Many thanks !
Would be nice if you could show how to display custom fields (only if they are filled) on a custom post type
Researching on Internet I got how to do it in other themes (using Advanced Custom Fields Plugin) but it seems does not work on The7 🙁
Many thanks
Regards
Varo
Hi Varo
Glad it helped!
Advanced Custom Fields Plugin should work with The7 as well just like other themes. Can you please clarify difficulty you are facing ?
Thanks
Hi Safeer!
Thanks for your quick reply.Let see if I can clarify the difficulty.
Let say I have created a custom field named “description”. If I paste the following code within the template , then ACF works fine as it displays “description” ONLY if the field has been filled (otherwise not displays it)
GENERAL DESCRIPTION
With the above option I can only use the custome fields to be displayed “before” or “after” the content and the problem appears when I paste the same code “within the Visual Composer” as I would like to have some custom fields within “the content”.
I have pasted code in “Raw HTML” widget from Visual Composer and nothing happened
Hope the above clarify the issue I have and will look forward to see your comments
Thanks and regards!
Varo
Not sure why the code did not appear in my previous reply to you. Lets try again
GENERAL DESCRIPTION
Hi Varo,
Sorry for the late reply, are you able to sort this out ?
You cannot display custom filed content using Raw HTML, you will need to edit the template, single.php or custom-single.php
HTML/PHP code will stripe out from comments, please use gist to share code.
Hi Safeer!
Sorry about the late reply but I was a bit busy (I am trying to improve my WordPress skills in the free time 🙂 )
I understood what you explained about content using Raw HTML. Many thanks
Do not want to bother you but would really appreciate if you could advise a tip/clue about how to display a custom taxonomy in Portfolio Masonry template.
It only gives you the options to select within ‘dt_portfolio_category’ bout would be useful if you can also pick from a new custom taxonomy that I added to Portfolio.
I tried to find info in the web and also tried many changes by my own with no luck at all
Many thanks
Regards
Varo
As I mentioned before you’ll need to edit edit the template, single.php or custom-single.php
Taxonomy can fetch like this
$terms = get_the_terms( $post->ID, 'my_taxonamy' );
Please refer to codex for details
Hello Safeer,
Thanks for the tutorial.
Can you tell me the syntax for ” = ‘cp_test’; ” if we have several custom post types ?
Thanks 🙂
Hi Olivier,
Please try each in new line like
$DT_META_BOXES[ $mb_id ][‘pages’][] = ‘cp_test’;
$DT_META_BOXES[ $mb_id ][‘pages’][] = ‘cp_anothercpt’;
Any idea how to make the Post Options metabox to appear on a custom post editing page?
Hi Steve,
That is quite complicated, Post options are dedicatedly designed for posts. Adding the meta box won’t make the options work in the front end.
Thanks
Hello Safeer,
I too thank you for offering these solutions for The7, they’re much needed in my work. When attempting to add meta boxes to more than one custom post type, i cannot find a solution.
I have tried (cpt name is correct) :
function add_dt_metaboxes_custom( $pages ) {
$DT_META_BOXES[ $mb_id ][‘pages’][] = ‘faculty’;
$DT_META_BOXES[ $mb_id ][‘pages’][] = ‘major’;
return $pages;
}
add_filter( ‘presscore_pages_with_basic_meta_boxes’, ‘add_dt_metaboxes_custom’ );
Hello Brian,
Sorry for the late reply, Please try like
function add_dt_metaboxes_custom( $pages ) {
$pages[] = 'faculty';
$pages[] = 'major';
return $pages;
}
add_filter( 'presscore_pages_with_basic_meta_boxes', 'add_dt_metaboxes_custom' );
Thank you Safeer, that works perfectly
Hi,
Glad it helped!
Thank you! Still works great.
Hi,
Glad it helped!
Hi, Safeer! )
Hope you can help me understand how to tackle my issue.
I have The7 theme and custom post type called ‘ajde_events’.
And I need to make presets of the following metaboxes for it when I create a new entry:
> sidebar = disabled
> dt_page_overrides_top_margin = 0
> dt_header_title = disabled
Can you help me with this?
Thank you in advance!
P.S. I’m not 100% sure if metaboxes’ names are correct.
Hi once again!
I’ve found the solution.
Here it is:
add_action( ‘get_header’, ‘seminar_meta_presets’, 50 );
function seminar_meta_presets() {
$config = Presscore_Config::get_instance();
if( ‘seminary’ == get_post_type() ) {
$config->set( ‘sidebar_position’, ‘disabled’ );
$config->set( ‘footer_widgetarea_id’, ‘sidebar_8’ );
$config->set( ‘page.top_margin’, ‘0’ );
$config->set( ‘header_title’, ‘disabled’ );
}
}
add_action( ‘get_header’, ‘ajde_events_meta_presets’, 50 );
function ajde_events_meta_presets() {
$config = Presscore_Config::get_instance();
if( ‘ajde_events’ == get_post_type() ) {
$config->set( ‘sidebar_position’, ‘disabled’ );
$config->set( ‘footer_widgetarea_id’, ‘sidebar_5’ );
$config->set( ‘page.top_margin’, ‘0’ );
$config->set( ‘header_title’, ‘disabled’ );
}
}
Last update I can’t use meta boxes to custom post types.
Hi, Still works
Its posible add portfolio options meta-box? not only the basics metabox?
or, in the same idea, its posible use a new custom post type, like a portfolio post?
Thnks
Hi Safeer!
Is there a way to do that with just a single post via the post_id?
Thanks in advance
Hi,
Do you mean for the default post? you can edit the post and enable it from sidebar options.
https://guide.the7.io/blog/user-guide/widgets/individual-widget-areas/
If it is a custom post type, please try this approach (adjust the if condition to match your needs)
https://gist.github.com/thecodepoetry/22463be7cbeda46bbaf00f6641d1ce26
If you need any further assistance, please submit a ticket here https://support.dream-theme.com/