How to change value of $ratingvotesav in showthread ?

I'm coding my own plugin.

I want to create a rating rich snippet in specific post/forum.

Here is the code of my plugin:

	function rating_snippet(&$thread)
	if($thread['numratings'] > 0)
		$offer_name = $thread['subject'];
		$offer_rating = $thread['averagerating'];
		$offer_count = $thread['numratings'];
		$ratingvotesav = "<div itemprop=\"aggregateRating\" itemscope itemtype=\"\">
			<div>Rating : 
			  <span itemprop=\"ratingValue\">" . $offer_rating . "</span>/
			  <span itemprop=\"bestRating\">5</span>
			  (<span itemprop=\"ratingCount\">" . $offer_count . "</span> vote(s))

Since it's currently local, of course value $ratingvotesav is not update in showthread.

I tried to put $ratingvotesav in method call (function rating_snippet(&$thread, &$ratingvotesav) ) but it's not working.

Any idea ?

Another solution to my problem could be to dynamically change template from "showthread_ratethread" to "showthread_ratethread_with_snippet" in my plugin, but I don't know if it is possible, and how to do this...
You need to globalize the variable $ratingvotesave.

How can I do this ?

function rating_snippet(&$thread)
	global $ratingvotesav;
	$ratingvotesav .= "test"; 

change nothing...
Because your code is just wrong - you mentioned in the 1st post that you want to change something in showthread, yet none of the showthread hooks accepts/expects a parameter.. So $thread including $thread['numratings'] is always empty and the conditional fails with a PHP notice. This means you need to globalize $thread too and remove it from the parameter.

Also, not sure what you want to achieve, but editing a global variable to add HTML is never the best solution. You should rather edit the template with the find_replace_templatesets() function (+ possibly create a new template for the added HTML, eval() it into a variable and add that variable to the core template).

But from the looks of code from the 1st post, you don't even need a plugin and you can paste that HTML directly to the template, using the core variable which you're duplicating for some reason ($thread['averagerating'] and $thread['numratings'])..
Thank, I succeed coding my plugin with your help.

Forum Jump:

Users browsing this thread: 1 Guest(s)