News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

How insert code on last post

Started by Massl, February 27, 2019, 05:48:40 AM

Previous topic - Next topic

Massl

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

vii

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)

Massl

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.

vii

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.

SychO

do you mean the last post of every page or literally the last post of the whole topic ?
Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze

Massl

I mean last post of every page.

@Virginiaz thanks

Massl

I tried everything but nothing, I didn't imagine it was so difficult...  ???

SychO

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>';
Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze

vbgamer45

Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Massl

Thanks SychO, without your help I would never have succeeded  ;)

Advertisement: