@crazycells Ok, here goes
- In your ACP, go to Appearance->Custom Content->Custom Javascript
Add this code, changing “224” to the actual ID you want to target
$(document).ready(function(){
$(window).on('action:ajaxify.end', function (data) {
var thisid = $('#topic_id').val();
if(thisid == 224 // Change this value to the topic ID you want to target ) {
$("#thiswidget").removeClass("hidden");
$("#thiswidget").addClass("show");
}
else {
// Nothing to do here
}
});
});
Ensure you have enabled both of these
Save
- In the ACP, go to Appearance->Custom CSS/LESS
- Add new CSS classes as below at the top of the window
.hidden {
display: none;
}
.show {
display: block !important;
}
- In the ACP, go to Extend->Widgets.
- Choose
topic.tpl
from the widget target selection
- Create a new HTML widget and drag this into the
Topic Footer
section (or wherever you want it to appear)
Paste this code inside the HTML area
<input type="hidden" id="topic_id" name="topic_id" value="{tid}">
<div class="hidden" id="thiswidget">This text should only appear if the ID matches</div>
- Save the widget layout, and now reload the site.
- Select the topic you are specifically targeting, and open it
If all went according to plan, you should see the below text appended at the bottom of the screen just before any other widget you may have in that area
What have we done here ?
Essentially, we have injected two new lines of code into the topic stream using the topic widget
We set a class of hidden
so that the widget won’t display unless there is a match to the ID we are targeting
Then, this jQuery code looks for the ID we want, and if there is a match, it removes the hidden
class and replaces it with show
meaning it will display
Adding hidden input fields into the HTML stream and then using jQuery to obtain the value is an old trick, but very reliable, and low in terms of performance needs. You may wonder where the {tid}
value comes in ? This is from the API itself - more detail here
Basically, this part
Final parts
Obviously, you’ll want to fashion the widget to present to your tastes - this is fine, but don’t delete anything here other than
This text should only appear if the ID matches
inside the code block
Hope this helps.