Page 1 of 1

How to change the color of First post of the topic

Posted: Wed Nov 22, 2017 12:46 pm
by KhurramMunawar
Is there any possibility to change the color of the first post of the topic ? (first post only )

many thanks

Re: How to change the color of First post of the topic

Posted: Wed Nov 22, 2017 2:45 pm
by david63
Which colour do you want changing? Text? Background? Border? or something else?

Is this "new" colour an existing colour of the style or is it any colour that the User chooses?

Is the colour defined by the Admin or the User when posting?

Does the same colour apply to all fora or is it selectable by forum?

It would help when making an extension request if you could be specific as to what you want - that way you may stand a chance of somebody actually doing it.

Re: How to change the color of First post of the topic

Posted: Wed Nov 22, 2017 2:58 pm
by ViolaF
i think, he means the background-colour of the post itself ;)

Re: How to change the color of First post of the topic

Posted: Wed Nov 22, 2017 3:16 pm
by Ger
Should be quite easy to pass the $topic_data['topic_first_post_id'] to the template and add a class indicating the first post to the post div. You can assign any CSS you like to that class.

Re: How to change the color of First post of the topic

Posted: Wed Nov 22, 2017 3:17 pm
by KhurramMunawar
i just want to make the first post prominent than the replies.
and that could be by changing the post Background color or the text color.

and that should apply to all first posts of all the topics in the fora.

Thanks

Re: How to change the color of First post of the topic

Posted: Wed Nov 22, 2017 3:19 pm
by KhurramMunawar
Ger wrote:
Wed Nov 22, 2017 3:16 pm
Should be quite easy to pass the $topic_data['topic_first_post_id'] to the template and add a class indicating the first post to the post div. You can assign any CSS you like to that class.
thanks for the suggestion.
I am not very good in doing as you directed. I need complete tutorial :mrgreen:

Re: How to change the color of First post of the topic

Posted: Wed Nov 22, 2017 3:34 pm
by Ger
Well, you create an extension (might want to use the Skeleton Extension tool) that uses the event core.viewtopic_modify_post_row
Than create a function that's called upon that event:

Code: Select all

public function is_first_post($event)
{
    $post_row = $event['post_row'];
    $topic_data = $event['topic_data'];
    $post_row['S_TOPIC_FIRST_POST'] = ($post_row['POST_ID'] == $topic_data['topic_first_post_id']);
    $event['post_row'] = $post_row;
}
Next, you create 2 template files that hook into viewtopic_body_postrow_post_before and viewtopic_body_postrow_post_after to add a surrounding div like

Code: Select all

<!-- IF S_TOPIC_FIRST_POST --><div class="topic_first_post"><!--ENDIF -->
and

Code: Select all

<!-- IF S_TOPIC_FIRST_POST --></div><!--ENDIF -->
And you create a CSS file that has something like

Code: Select all

.topic_first_post .post {
	background-color: #F00; 
}
Please note that I've just written this from the top of my head so totally untested and it might just as well be bugged :mrgreen:

Re: How to change the color of First post of the topic

Posted: Wed Nov 22, 2017 3:55 pm
by KhurramMunawar
Thank you so much for the great help.