Show A Specific Tab When A Feature Image is Added
Support › MB Conditional Logic › Show A Specific Tab When A Feature Image is AddedResolved
- This topic has 15 replies, 2 voices, and was last updated 7 years, 2 months ago by
Anh Tran.
-
AuthorPosts
-
January 2, 2018 at 11:04 PM #8096
tsquez
ParticipantHI there,
I am using
meta-box-tab
as well asmeta-box-conditional-logic
extensions. In my theme the user can select where theFeatured Image
of a post or page is displayed. Here is the code I am added to the theme:https://ghostbin.com/paste/daepa
As you can see the user has two options: they can show the featured image below the title or display it above the title.
My question is how can I hide the
Featured Image Options
tab if there is no featured image and show theFeatured Image Options
tab if a featured image is used?Thanks for any help you can provide.
January 3, 2018 at 2:56 PM #8110Anh Tran
KeymasterHi Thomas,
Let me see if I can find a workaround for this.
January 3, 2018 at 10:42 PM #8117tsquez
ParticipantAwesome sir thank you. I appreciate any help.
January 5, 2018 at 9:44 AM #8130Anh Tran
KeymasterHi Thomas, I've just updated the plugin, adding support for Featured Image. Please see the documentation for usage.
Cheers
January 5, 2018 at 11:15 PM #8136tsquez
ParticipantOh wow, unexpected. Thank you sir. I will take a look at it later today and let you know what I think.
Again, thank you for the update.
January 6, 2018 at 1:29 AM #8137tsquez
ParticipantSo if I am trying to HIDE the
Featured Image Options
TAB, where would I add the code from https://docs.metabox.io/extensions/meta-box-conditional-logic/#featured-image in the following:https://ghostbin.com/paste/pss7p
I have tried adding it to
Featured Image Options
tab but it still shows.What am I doing wrong?
P.S. yes i updated the conditional extension.
January 6, 2018 at 10:55 AM #8142Anh Tran
KeymasterHi Thomas,
Your case is a combination of the featured image rule with this tutorial.
I added the solution to the library. Please take a look.
(Note: I removed all textdomain and prefix to help others see the code clear).
January 6, 2018 at 11:10 AM #8143tsquez
ParticipantHi there,
Ah OK I see it now...lol! Thank you very much, greatly appreciated my friend.
January 7, 2018 at 3:16 AM #8147tsquez
ParticipantOK just wanted to stop in and say THANK YOU, THANK YOU, THANK YOU!!! This works beautimously...lol!
Great job guys, you killed it. Seriously, this is AWESOME!!! Thanks again.
January 7, 2018 at 10:29 PM #8149tsquez
ParticipantLike I said before it works perfect, but I do have a question and I am hoping you can provide me with an answer as I am sure someone else will probably ask this.
OK so before I add my featured image, this is what the metabox looks like:
https://imgur.com/OR5CWv9 (screenshot 1)
and when I add my featured image it looks like this:
https://imgur.com/gNK9URW (screenshot 2)
This is pretty cool, however, I am wondering, how can I make the "Hide Post/Page Elements" tab be the "active" tab and show the contents of that tab if there is NO featured image.
In other words: If there is NO featured Image, how can I make it look like this:
https://imgur.com/f0Ny2ur (screenshot 3)
when there is no featured image I would like the next tab to be the active tab and show the tab content. Is this possible?
I hope there is a way to do it. Thanks again guys.
January 10, 2018 at 2:39 PM #8177Anh Tran
KeymasterI got it. The first tab is always the active one when page loads. It's styled by a CSS class. I think the best solution for this issue is reorder the tabs, e.g. move another tab to the top, so when Featured Image tab is hidden, the first tab is still the active one.
January 10, 2018 at 10:45 PM #8183tsquez
ParticipantHey there,
Yes I thought about that before asking the question and I even tried it to see what happens.
This is what happens:
1. I move the featured image tab to the last position. I remove the featured image and now the featured image tab is hidden because there is no featured image:
https://i.imgur.com/N28Q70X.png
2. So I add a featured image and the Featured Image Options tab appears:
https://i.imgur.com/Rzlfx0z.png
As you can see this is not the desired effect. Which is why I asked the question in the first place amigo. Trust me I never ask a question on how to do something if I haven't already tried doing everything possible to make it work 😉
So, is there a way to maybe set a tab to be the active tab, maybe like this:
'active' => true,
Thanks again.
January 12, 2018 at 2:42 PM #8196Anh Tran
KeymasterHi Thomas,
I've been thinking about this, too. It seems that I have to add some more code to target this situation. Let me try to do that.
January 13, 2018 at 6:51 AM #8207tsquez
ParticipantAwesome amigo I look forward to seeing what you come up with.
I know you'll knock it out of the ballpark
January 21, 2018 at 1:52 AM #8274tsquez
ParticipantOK so my theme <b>TotalPress</b> was reviewed yesterday. I was excited. However they are using a new plugin for review. You can find it here: https://github.com/WPTRT/theme-sniffer
You can run checks against different version of PHP, from 5.2 all the way to 7.
So they ran the theme through this new plugin and it ran into a few errors running it against php 5.2. One of the errors was generated from the code for MB Conditional Logic plugin.
It's this code from the library, at the very bottom: https://github.com/wpmetabox/library/blob/master/extensions/conditional-logic/featured-image-with-tabs.php
Specifically:
// hide our featured image options tab if there is no featured image being used. add_filter( 'rwmb_outside_conditions', function ( $conditions ) { $conditions['.rwmb-tab-totalpress_featured_image_options'] = array( 'visible' => array('_thumbnail_id', '!=', '-1'), ); $conditions['.rwmb-tab-panel-totalpress_featured_image_options'] = array( 'visible' => array('_thumbnail_id', '!=', '-1'), ); return $conditions; } );
This is what the error states:
Closures / anonymous functions are not available in PHP 5.2 or earlier
So I had to remove this from the theme as well as the plugin meta box conditional logic. I really would like to include this in the theme but for now to get the theme approved, I have removed it.
Any idea what it means...lol - know how I can correct it?
Any help you can provide is greatly appreciated.
-
AuthorPosts
- You must be logged in to reply to this topic.