Help with code to insert banner on 1st, 2nd and last post

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
User avatar
horseguards
Registered User
Posts: 95
Joined: Sun Oct 26, 2008 12:18 pm
Location: Mar del Plata [Argentina]
Name: P C

Help with code to insert banner on 1st, 2nd and last post

Post by horseguards »

I had this in an old phpBB, and I would like to reuse it to place a banner inside the 1st, 2nd and last post of each thread.

It doesnt't work, and I am not a coder, so I don't know if there is anything missing.

When I insert the first part in viewtopic.php I get error 500 :?

what changes should I make to use it?

I have phpBB 3.2.4 and PHP 7.2.14

Thanks!

********************************************************************
insert in viewtopic.php
********************************************************************

/**
* Hack to add a post counter to the postrow
* used to select in the template weather to show a post or not
*/
$post_counter = 0;
// End Hack


/**
* Hack to add a post counter to the postrow
* used to select in the template weather to show a post or not
*/
'POST_COUNTER' => $post_counter++,
'LAST_POST' => $post_counter==count($post_list),
// End Hack


********************************************************************
insert in viewtopic_body.html
********************************************************************

<!-- IF postrow.POST_COUNTER == 0 -->
--------------------
code
--------------------
<!-- ENDIF -->
{postrow.MESSAGE}
<br>
<!-- IF postrow.POST_COUNTER == 2 -->
--------------------
code
--------------------
<!-- ENDIF -->
<!-- IF postrow.LAST_POST -->
--------------------
code
--------------------
<!-- ENDIF -->
Last edited by Mick on Tue Feb 05, 2019 3:13 pm, edited 2 times in total.
Reason: Moved from support.
User avatar
Mick
Support Team Member
Support Team Member
Posts: 26505
Joined: Fri Aug 29, 2008 9:49 am

Re: Help with code to insert banner on 1st, 2nd and last post

Post by Mick »

Please read ReadMe Before Posting and make sure you post in the correct forum.
  • "The more connected we get the more alone we become" - Kyle Broflovski©
  • "The good news is hell is just the product of a morbid human imagination.
    The bad news is, whatever humans can imagine, they can usually create.
    " - Harmony Cobel
User avatar
horseguards
Registered User
Posts: 95
Joined: Sun Oct 26, 2008 12:18 pm
Location: Mar del Plata [Argentina]
Name: P C

Re: Help with code to insert banner on 1st, 2nd and last post

Post by horseguards »

Mick wrote: Tue Feb 05, 2019 3:16 pm Please read ReadMe Before Posting and make sure you post in the correct forum.
You're right! I am sorry!
User avatar
horseguards
Registered User
Posts: 95
Joined: Sun Oct 26, 2008 12:18 pm
Location: Mar del Plata [Argentina]
Name: P C

Re: Help with code to insert banner on 1st, 2nd and last post

Post by horseguards »

I found a way to make it work! :D :D

In case someone wants to use it...


===============================
in viewtopic.php (phpBB 3.2.4)
===============================

Code: Select all

		'S_TOPIC_POSTER'	=> ($topic_data['topic_poster'] == $poster_id) ? true : false,
		'S_FIRST_POST'		=> ($topic_data['topic_first_post_id'] == $row['post_id']) ? true : false,

/**
 * Hack to add a post counter to the postrow
 * used to select in the template weather to show a post or not
 */
		'POST_COUNTER'		=> $post_counter++,
		'LAST_POST'			=> $post_counter==count($post_list),
// End Hack		
		
		'S_IGNORE_POST'		=> ($row['foe']) ? true : false,
and the second part of the code, here

Code: Select all

$first_unread = $post_unread = false;
/**
 * Hack to add a post counter to the postrow
 * used to select in the template weather to show a post or not
 */
$post_counter = 0;
// End Hack
for ($i = 0, $end = count($post_list); $i < $end; ++$i)
The other part of the code, where the Ads code is, should be inserted in viewtopic_body.html, wherever you want the ads to be shown, on the 1st, 2nd and last post.
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: Help with code to insert banner on 1st, 2nd and last post

Post by mrgoldy »

It looks to me that this is inserting stuff on a per-page basis, rather than the entire topic, which you said you in your initial post.
So on the first, second and last post on a page rather than just the first post, second post and last post in the entire topic.
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
horseguards
Registered User
Posts: 95
Joined: Sun Oct 26, 2008 12:18 pm
Location: Mar del Plata [Argentina]
Name: P C

Re: Help with code to insert banner on 1st, 2nd and last post

Post by horseguards »

This is too complex for me, I don't know if I do understand what do you mean.

If I have a thread with 50 posts, and want the ads on the 1st, 2nd and last post of each page. I don't know if this is what you are talking about.

What would you suggest to improve it?

thanks!
User avatar
Lumpy Burgertushie
Registered User
Posts: 69223
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: Help with code to insert banner on 1st, 2nd and last post

Post by Lumpy Burgertushie »

the problem is that you keep talking about a topic with 50 posts but normally a page only displays 25 by default.

you can change that, but if you set it to 50 what happens when a topic contains 51 posts. now you have 50 on one page and one on another page.

not to mention that 50 posts on a page would be a lot of scrolling to see them all.

so, do you want this in the first, second and last post on a page or in a topic?


robert
Premium phpBB 3.3 Styles by PlanetStyles.net

I am pleased to announce that I have completed the first item on my bucket list. I have the bucket.
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: Help with code to insert banner on 1st, 2nd and last post

Post by mrgoldy »

horseguards wrote: Wed Feb 06, 2019 11:04 pm If I have a thread with 50 posts, and want the ads on the 1st, 2nd and last post of each page. I don't know if this is what you are talking about.
That’s exactly what i am talking about :).
You want it on every page of a topic so the current code works. That’s why being elaborate is important, as now you’ve mentioned “ads” instead of “some code”. That way we can deduct it would make sense to have it on every page.

Anyways, looks like you’re all set. Enjoy!

On a side note, perhaps have a look at the official extension from phpBB itself: Advertisement management. I believe that offers exactly what you’re asking for without having to make adjustments to the core file.

And if you are sticking to these core adjustments, make sure to write them down somewhere as you are likely having to re-do them when you update to a newer version of phpbb.
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
warmweer
Jr. Extension Validator
Posts: 11234
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium
Contact:

Re: Help with code to insert banner on 1st, 2nd and last post

Post by warmweer »

horseguards wrote: Wed Feb 06, 2019 11:04 pm If I have a thread with 50 posts, and want the ads on the 1st, 2nd and last post of each page. I don't know if this is what you are talking about.
This is presuming post sort order is by time and ascending. If it's descending then the 2nd banner would be in a different post.
Also take into account that changing the number of post per page implies that the banners will move to a different post (the 2nd banner) [not that it makes much difference for the viewer].
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
User avatar
horseguards
Registered User
Posts: 95
Joined: Sun Oct 26, 2008 12:18 pm
Location: Mar del Plata [Argentina]
Name: P C

Re: Help with code to insert banner on 1st, 2nd and last post

Post by horseguards »

Lumpy Burgertushie wrote: Thu Feb 07, 2019 12:35 am you can change that, but if you set it to 50 what happens when a topic contains 51 posts. now you have 50 on one page and one on another page.
Maybe I haven't explained myself properly.
I don't set it to 50. Each thread shows 10 posts per page. In each page of the thread, I want an ad on the 1, 2 and last post. No matter what number of posts the thread has.
User avatar
horseguards
Registered User
Posts: 95
Joined: Sun Oct 26, 2008 12:18 pm
Location: Mar del Plata [Argentina]
Name: P C

Re: Help with code to insert banner on 1st, 2nd and last post

Post by horseguards »

mrgoldy wrote: Thu Feb 07, 2019 12:47 pm On a side note, perhaps have a look at the official extension from phpBB itself: Advertisement management. I believe that offers exactly what you’re asking for without having to make adjustments to the core file.

And if you are sticking to these core adjustments, make sure to write them down somewhere as you are likely having to re-do them when you update to a newer version of phpbb.
I try to add as little extensions as I can. I did save both edited pages in a "backup" folder, for the next upgrade.
Thanks!
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: Help with code to insert banner on 1st, 2nd and last post

Post by mrgoldy »

"You do you" is the saying I believe.
But I would highly suggest to rather use the extensions than modifying core files yourself.
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
horseguards
Registered User
Posts: 95
Joined: Sun Oct 26, 2008 12:18 pm
Location: Mar del Plata [Argentina]
Name: P C

Re: Help with code to insert banner on 1st, 2nd and last post

Post by horseguards »

I will have a look at it.

Thanks you and the other guys for the advice!
Post Reply

Return to “phpBB Custom Coding”