Hi @sfdsfwer,
Is it possible to get this in there somehow?
The short answer is yes, it’s possible. However, to tell you exactly what you need to do I need to know how that shortcode works. Is it from another plugin? Or is it some custom code you/your developer wrote for your website?
Is it possible to place a link to the article on the individual surrounding DIVs of the cards?
Yep, you could just do something like this:
'post_html' => '<div class="col-md-4" onclick="window.location.href={url}"> ... </div>'
However, I’d avoid placing inline JavaScript code like that for various reasons. Personally I’d do it like this instead.
Thread Starter
anyway
(@sfdsfwer)
Hi Héctor,
thanks for your quick reply and of course for the awesome plugin!
I’m sorry, I posted the wrong plugin link… this is the right one:
https://wordpress.org/plugins/reading-time-wp/
About the surrounding link: I actually wanted to avoid using jQuery (or JS), but with this it works of course… thank you!
One more question: is there a list with all parameters? I haven’t found one in the wiki.
-
This reply was modified 2 years, 2 months ago by
anyway.
Thanks, that helped.
Alright, so one way we can use that shortcode with the wpp_get_mostpopular()
template tag is by creating a custom Content Tag (see Display Tags and Author image for a more detailed explanation + real life examples).
So, in your case, that would look like this:
/**
* Parses custom content tags in WordPress Popular Posts.
*
* @param string $html The HTML markup from the plugin.
* @param integer $post_id The post/page ID.
* @return string
*/
function wpp_parse_tags_in_popular_posts( $html, $post_id ){
// Replace custom content tag {reading_time} with
// the output of the [rt_reading_time] shortcode
if ( false !== strpos($html, '{reading_time}') ) {
$reading_time = do_shortcode('[rt_reading_time post_id=' . $post_id . ' label="Reading Time:" postfix="Minutes" postfix_singular="Minute"]');
// Replace {reading_time} with the value of $reading_time
$html = str_replace( '{reading_time}', $reading_time, $html );
}
return $html;
}
add_filter( "wpp_parse_custom_content_tags", "wpp_parse_tags_in_popular_posts", 10, 2 );
Add this code to your theme’s functions.php file and then update your post_html
parameter to include our new {reading_time}
Content Tag so it looks something like this:
'post_html' => '<div class="col-md-4"><div class="post-thumbnail">{thumb}</div><div>{taxonomy}</div><h3 class="h6">{title}</h3><p class="reading-time">{reading_time}</p><div>{excerpt}</div></div>',
One more question: is there a list with all parameters?
Yep, there is. Go to your WordPress Dashboard > Settings > WordPress Popular Posts > Parameters. You’ll find everything there. (Although I should add this to the Wiki so it’s easier to find, maybe I’ll look into it.)
Yep, there is. Go to your WordPress Dashboard > Settings > WordPress Popular Posts > Parameters. You’ll find everything there. (Although I should add this to the Wiki so it’s easier to find, maybe I’ll look into it.)
… and done! Parameters (this took forever to do).
Thread Starter
anyway
(@sfdsfwer)
Thanks for your effort, that worked perfectly!
I will soon install “Advanced Custom Fields” in the project and would like to display another field in the row of three cards. Will this work the same way with ACF fields?
And sorry about the parameters: I must have missed the obvious yesterday. There it is, big and clear and really well documented.
Thanks for your effort, that worked perfectly!
Don’t mention it, glad I could help!
And sorry about the parameters: I must have missed the obvious yesterday. There it is, big and clear and really well documented.
It’s OK, don’t worry about it 🙂
I will soon install “Advanced Custom Fields” in the project and would like to display another field in the row of three cards. Will this work the same way with ACF fields?
Yes you can create a custom Content Tag the same way to display your custom field, like this for example: ACF field integration?
Thread Starter
anyway
(@sfdsfwer)
This looks promising. I will try it out in the next few days. Thanks again and have a great weekend!
Thread Starter
anyway
(@sfdsfwer)
“Advanced Custom Field” Integration worked great! Once you understand the concept of Custom Content Tags, it’s really easy to work with. Very flexible. Thanks again for your support!
Once you understand the concept of Custom Content Tags, it’s really easy to work with. Very flexible.
That’s the idea 😀 Glad you found it useful!