Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blog shortcode no-post message #18

Closed
ghost opened this issue Jan 4, 2018 · 9 comments
Closed

Blog shortcode no-post message #18

ghost opened this issue Jan 4, 2018 · 9 comments

Comments

@ghost
Copy link

ghost commented Jan 4, 2018

When the Blog shortcode has no posts to show it prints out the message Please add blog posts for them to display here.
It is not very relevant for my add-on since we are dealing with custom post types rather then with blog posts.
Is it customizable somehow?
Can you please advise on the best way to do it?

@yawalkar
Copy link
Contributor

yawalkar commented Jan 4, 2018

The placeholder is added via function fusion_builder_placeholder in Fusion Builder. You can override the function by adding a check like below and do your check for the post type and replace the messages accordingly -

if ( ! function_exists( 'fusion_builder_placeholder' ) ) {
	function fusion_builder_placeholder( $post_type, $label ) {
		if ( current_user_can( 'publish_posts' ) ) {
			$string = sprintf( esc_html__( 'Please add %s for them to display here.', 'fusion-builder' ), $label );
			$link = admin_url( 'post-new.php?post_type=' . $post_type );
			$html = '<a href="' . $link . '" class="fusion-builder-placeholder">' . $string . '</a>';
			return $html;
		}
	}
}

Or, if you just want to use the placeholder text in your add-on, you can simply make a function call and pass your post type label here -
fusion_builder_placeholder( $post_type, $label );

I hope this will help.

@pixfil
Copy link

pixfil commented Feb 7, 2018

Hi yawalkar,

is it possible to have more information about that?
how can we use your code above? in code snippet or functions.php?

Thank you!

@mikka23
Copy link
Contributor

mikka23 commented Feb 7, 2018

Hi @pixfil

It really depends on what you wish to accomplish. There usually no need to override that particular function unless editing/overriding an existing element. So if it doesn't fit your purposes you should be able to use your own function.

If you do want to use the function fusion_builder_placeholder then it can be used by passing in the values of the relevant post type. For example, for regular posts it is:

fusion_builder_placeholder( 'post', 'blog posts' );
  • 'post' = the post type so that the add new item link works correctly
  • 'blog posts' = the text used in the warning, so it would be - Please add blog posts for them to display here.

Unfortunately, the code @yawalkar won't be possible right now since the function within Fusion Builder is not pluggable.

Can you provide some more information about the particular situation you are facing a problem with?

@pixfil
Copy link

pixfil commented Feb 7, 2018

Thank you mikka23 for your quick reply.

Yes, I can tell a bit more about me and my issue: I'm using Avada and want to display something else than "Please add blog posts for them to display here" if I got no post to display.
(I wrote a bit too fast, I just see after my message that it doesn't display if I'm not connected = understand : that could be enough.)

But! Ideally I'd like to display something for my guests like "no events right now" because I use a specific category post to display an upcoming event, which move to another category and another place in my website after the date is passed. So I got a "blank" on the initial "slot" -upcoming event-.

Another important thing: I'm not a developer and I don't really understand functions construction.. "add action" and all the others things. I just know how to put it when I found what I want "ready to use"..

Hope I was clear enough.

If you can help I'll really appreciate, instead I'll keep it blank.

Thank you

@mikka23
Copy link
Contributor

mikka23 commented Feb 7, 2018

Have you created your own element for this purpose? Or are you using an existing builder element but swapping the post type?

@pixfil
Copy link

pixfil commented Feb 7, 2018

i'm using the default element "Blog" (which display one post from a specific categorie "competition") that's all. No particular customisation.
For the "swapping", it's done with the plugin "Post Expirator" which swap the category, so the post go to my area "past event"

@mikka23
Copy link
Contributor

mikka23 commented Feb 8, 2018

Hi @pixfil

In that case i am afraid that is not really possible when using the default fusion blog shortcode. Even if the placeholder could be overridden right now it does not check for a specific category. So in your case you would not be able to alter the output just for a single category.

Instead, you would be better of filtering the entire shortcode output using a core WP filter. For example:

function empty_specific_category_blog( $output, $tag, $attr, $m ) {
	if ( empty( $output ) && 'fusion_blog' === $tag && isset( $attr['cat_slug'] ) && 'competition' === $attr['cat_slug'] ) {
		return 'No competitions to show.';
	}
	return $output;
}
add_filter( 'do_shortcode_tag', 'empty_specific_category_blog', 10, 4 );

You can add that to a child theme functions.php. It will check if the output is empty (so this will only show if you are logged out, because placeholder is shown if logged in so output is not empty). If the shortcode tag is fusion_blog and that the category selected is competition (assuming only a single category is selected)

@pixfil
Copy link

pixfil commented Feb 8, 2018

Hi mikka23,

Thank you a lot, filtering the entire shortcode output works almost like a charm!

I've two little problems which I try to resolve yet:

- utf8 character issue : i got a "-?-" instead of my accent
(competitions =>FR=> compétitions => comp-?-titions)
=> [EDIT: ok, notepad problem resolved]

  • and I can't centering the sentence... try to add a CSS Class to the blog shortcode but it seems not working.
    (I try "content: center; text-align: center;)

Can we resolve those directly in the function?

Thanks again :)

@pixfil
Copy link

pixfil commented Feb 8, 2018

I wrote again too fast!

for the CSS, it's working when I use CSS ID on the column element.

column CSS ID: "competune"
Theme option > custom CSS:
#competune {
text-align: center;
}

Thank you a lot mikka23! problem solved for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants