Hi, I'm trying to insert some code on every last message of the topic's pages.
There is a way or $context that I can use?
With $context['topic_last_message'] it is only displayed in the last message of the topic
Thanks
Can't you put it directly after the message loop in Display.template.php? For an unmodded file, it should be on line 632. (Or just search for <a id="lastPost"></a>)
Otherwise, I suppose at the very top of the message loop in the template file, you could do:
Find:
// Get all the messages...
while ($message = $context['get_message']())
{
$ignoring = false;
$alternate = !$alternate;
Replace with:
global $messages_request, $smcFunc;
$numMsgs = $smcFunc['db_num_rows']($messages_request);
$curMsg = 0;
// Get all the messages...
while ($message = $context['get_message']())
{
$ignoring = false;
$alternate = !$alternate;
if ( (++$curMsg) == $numMsgs ) {
$message['body'] .= '<br />last msg (num: ' . $numMsgs . ')';
}
But FYI that is just a quickie example and not standard for SMF mods (counting rows should go in Display.php)
Quote from: Virginiaz on February 27, 2019, 08:20:28 AM
Can't you put it directly after the message loop in Display.template.php? For an unmodded file, it should be on line 632. (Or just search for <a id="lastPost"></a>)
Thanks for your reply, I forgot to write that I'm using 2.1 RC1 and I can't find lastPost on Display.template.php
After
<div class="inner" data-msgid="', $message['id'], '" id="msg_', $message['id'], '"', $ignoring ? ' style="display:none;"' : '', '>
', $message['body'], '
</div>
</div><!-- .post -->';
I add
if ($message['id'] == $context['topic_last_message'] and $message['id'] != $context['first_message'])
echo 'Code';
but as I said it is only displayed in the last message of the topic.
If you want your code to come directly after all the messages for 2.1, put it in the </form></div> part of this:
// Get all the messages...
while ($message = $context['get_message']())
template_single_post($message);
echo '
</form>
</div>';
// Mobile action - moderation buttons (bottom)
As far as I know, the primary example I gave you with db_num_rows would still work but you need to tweak the code because 2.1 offloads template message display into another subroutine instead of doing it all in the loop.
do you mean the last post of every page or literally the last post of the whole topic ?
I mean last post of every page.
@Virginiaz thanks
I tried everything but nothing, I didn't imagine it was so difficult... ???
Use this anywhere inside template_single_post function
if($context['topic_last_message'] == $message['id'] || ($message['counter']+1) % $context['messages_per_page'] == 0)
echo '<div class="errorbox">I\'m the last message of this page</div>';
Thanks very helpful.
Thanks SychO, without your help I would never have succeeded ;)