How can i use "block trending now" via php

Posted in: Newspaper
Post count: 4

Hello,
How can i use “block trending now” via php or a shortcode. I would like to appear this block on every article page of my website.

Thank you in advance.

Post count: 4

I came up with a good solution for now. Go to
wp-content/themes/Newspaper/includes/widgets/td_page_builder_widgets.php

and add the following code

class td_block_trending_now_widget extends td_block_widget {
var $td_block_id = 'td_block_trending_now'; // change only the block id, the rest is autogenerated
}

add_action('widgets_init', create_function('', 'return register_widget("td_block_trending_now_widget");'));

this will make a “news ticker” widget and then you can use it via php with the wordpress function


<?php the_widget( 'td_block_trending_now_widget' ); ?>

Althoug its working if you need to customize it (ex. number of post shown) you have to pass a second var on the function which is the array containing the attributes with their values. My next question is
what are these attributes. For example if i want 10 posts from category “World” what should i write?


args = array(
post => 1,
cat => 'World'
);
the_widget( 'td_block_trending_now_widget', $args );

Post count: 22421

Hello,

The easier way to do it is with do_shortcode. THe news ticker is a rendered visual composer shortcode so using the function directly in the post template files is easier.
you cna set up your ticker the way you want it on a dummy page like so: http://screencast.com/t/iIKBu50mv and set all of it;s options.
The you can use the shortcode generated in classic mode and text mode: http://screencast.com/t/yLkdt8nsfK
Then you can place a do_shortcode function on each post template and add the shortcode inside: https://developer.wordpress.org/reference/functions/do_shortcode/
<?php echo do_shortcode('[td_block_trending_now style="style2" header_text_color="#dd3333" header_color="#1e73be" category_id="1048" sort="random_posts" limit="20" offset="2"]'); ?>

I hope this helps.
Thanks

Post count: 4

Thank you very much. Thats what i needed!

Viewing 4 posts - 1 through 4 (of 4 total)
The forum ‘Newspaper’ is closed to new topics and replies.