Show a block only when it has news

Posted in: Newspaper
Post count: 104

Recently I have posted here something about sticky posts and made a request that you should fix this in a future update. I am still trying to get a workaround for this. It corssed my mind that a good solution for this would be that one inserts a block on the top of the main block and then filters this new block by one category only (let’s say “Sticky” category). Then, the block would be visible only when there are news on that category.

I tried to do this but it seems that the block is always visible no matter what. Please tell me that there a way to solve this! Is there!

Post count: 9544

You would likely need to custom build some kind of new query based on a date range, like only show item/block if query to that featured category has a story newer than xx days. So else if nothing newer than xx days, show nothing.

Not sure you could do that in VC with a module — but you could likely create your own CSS for a custom block or something, and then maybe populate that spot in layout with that block?

This is not a normal thing since that is kind of what a ‘featured’ category has traditionally been used for in WP — meaning, you have a “sticky” category, and then you only have one item in it; then edit that post when you no longer want it featured.

Not sure that helps — but some food for thought anyway.

Post count: 104

I’m not sure I understand you whe you say:

This is not a normal thing since that is kind of what a ‘featured’ category has traditionally been used for in WP — meaning, you have a “sticky” category, and then you only have one item in it; then edit that post when you no longer want it featured.

The sticky posts feature is off and it does not work when changing the file td_data_source.php because I am filtering several categories. I desperatly need this feature though. So, I need a workaround for this!

I have got an answer on another forum (PHP forum) to try to solve this:

add_filter('get_terms', 'get_terms_filter', 10, 3);
function get_terms_filter( $terms, $taxonomies, $args )
{
global $wpdb;
$taxonomy = $taxonomies[0];
if ( ! is_array($terms) && count($terms) < 1 )
return $terms;
$filtered_terms = array();
foreach ( $terms as $term )
{
$result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts p JOIN $wpdb->term_relationships rl ON p.ID = rl.object_id WHERE rl.term_taxonomy_id = $term->term_id AND p.post_status = 'publish' LIMIT 1");
if ( intval($result) > 0 )
$filtered_terms[] = $term;
}
return $filtered_terms;
}

Would it work? My knowledge on PHP is very limited…

Any other solutions?

Post count: 104

OK, there is some light at the end of the tunel! I have found this plugin that works almost as I want: https://wordpress.org/plugins/posts-in-page/installation/

By using the shortcode [ic_add_posts ignore_sticky_posts=’no’] paste on a plain text box at Visual Composer, all sticky posts are shown!

The only if is that the post does not show the post thumb! Please TagDiv, can you adapt this plugin to your theme and include it as a solution for this issue? Please??

Post count: 104

This shortcode will also work well: [ic_add_posts category=’category-slug’]

Post count: 9544

Right. I just use the built-in “featured” category to manually select stories I want “featured” on our home page, such as in a mid-size slider at top; then set the slider to only show the items from the ‘featured’ category and nothing else.

So, that was my thinking on how to adapt that behavior. Sorry didn’t have perfect answer 🙂

TagDiv might have some more insight when they get back in the saddle.

  • This reply was modified 10 years by simchris.
Post count: 104

No prob, different websites have different needs. In my case, the customer doesn’t want any slider so that is out of the question for me. My customer also wants to have a layout extremely similar to his old website which in this case means only one main feed.

I would like to have another design (more modern and less irritating) but this is the result and it is exactly what he wants: http://värnamo.nu/

Post count: 7909

Hi,


@jonybigude
Thanks for your suggestion, I will add also this discussion(topic) on the sticky post request and we will try to find a solution for this as I see that many users demand it. We’ll see if we will implement a plugin or another solution as soon as possible.

Thanks!

Post count: 104

That is just awesome! How can I keep updated in this matter?

Post count: 7909

Hi,

Yes you can update this topic if you want as it is added to our issue list regarding the sticky post issue and the developer will take a look when they will try to solve this issue.

Thanks!

Post count: 10

Woudl be great and very usefull to have this option. Our example – we have big grid at top position on frontpage with featured posts. Then it happens an article with breaking news we want to be fixed as first at featured big grid, so new featured articles can be added but will not move breaking news from top first position, till we sticky uncheck it. Think all news editors would like to have this option, we included 🙂

http://www.epodravina.hr

Post count: 104

Hi! I am going to make a new Newspapper site. Did you solve this issue? I see you have made a series of updates, did you include the sticky posts on the updates? The option of being able to filter news in blocks by writing ID is not a solution since it forces my customers to “be technicians” and create/delete a block everytime they need a sticky post.

Any solution for this already?

Post count: 22421

Hi,
Unfortunately sticky posts have not been added in our theme yet as we have not found a solution yet for implementing them in our modules and blocks. It is not as easy as it seems because the blocks need to be adjusted with every setting/filter to keep track of this one sticky post, plus the new facebook, google and wp changes gave us a lot to work on fixing issues that we did not have much time to implement new options as you can see in the changelog: http://themeforest.net/item/newspaper/5489609
Thank you for your understanding.

Post count: 104

Well, can you recommend any workarround? A special category that is only shown if it has news for instance would save the day….

Post count: 22421

Hi.
Unfortunately there is no quick solution I can provide for this. The theme does not display anything from a category if there are no posts set to it, but hiding a category after a certain period of time and show it again once it is updated…this will be no easy task. You will have to hire a freelancer to help out on this one.
You can maybe make use of the new sorting option for modules and blocks in which you can set the post id’s to display in a particular block.
Thank you.

Post count: 104

Ok… what if we manage to add a class to a post everytime we want it to be sticky? Then we can create an alternative news flood and through CSS make it invisible (no styling). This flood shows news from the post category “sticky” only. Then the person who is writing the new post can check a radio button to add that class and attribute the “sticky” category. That class will then make the post display:block.

Would this work?

Post count: 104

I also found this: http://www.wpbeginner.com/wp-tutorials/how-to-display-a-category-only-if-it-has-posts-in-wordpress/

It’s another approach, would it work? How could I apply it?

Post count: 22421

Hello,

The methods you showed could work but you will have to try them out. Please understand that time does not allow us to offer any custom work at the moment as we are a small team and we work hard on development, updates, fixes and support. We would happily help you out but this is not an easy task to tackle. Your best bet would be to hire a freelancer to help you out. There are many sites which offer freelance work and the prices are different from one to the other.

Thank you for your understanding.

Post count: 104

I do completely understand what you are saying. Just thought on ask you since you know the code way much better than me and could say right away if my suggestions would be impossible. I am going to give it a try. If you want to give me a bit more help I would have no issues on making the code available for you or the whole community.

Thanks and keep up with the hard work!

Post count: 6600

@jonybigude

It’s not impossible but would require customizations and I would suggest to do this in each block’s template: http://screencast.com/t/ZBvrHE6M6C place a condition to verify if the query has posts and set it to return an empty string if it does.

Hope this helps! If you’re not aware how to do this please contract a developer/freelancer.

Thanks for the message!

  • This reply was modified 10 years by Lucian.
Post count: 104

That was a very useful answer Lucian, thanks! I will give it a try using this.

I wish you could add these features to the template. Right now pretty much all the newspaper themes have +/- exakt the same functions. Such features would throw you guys to a cutting edge position since nobody else is offering them…

Post count: 22421

Thank you for your suggestion.
We will consider this for a future update.

Viewing 22 posts - 1 through 22 (of 22 total)
You must be logged in to reply to this topic.