Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: kyle007 on March 28, 2008, 09:40:22 AM

Title: Any chance to change the "topic title color" ?!?
Post by: kyle007 on March 28, 2008, 09:40:22 AM
I want a topic's title red...Only one topic's...And also  wanna make it bold....

Any way to do this ?

_________________________________________

Solution :

Sources/MessageIndex.php :

Code (find) Select
// 'Print' the topic info.

and above it, add


$color = $row['ID_TOPIC'] == '6395' ? 'red' : '';
$weight = $row['ID_TOPIC'] == '6395' ? 'font-weight: bold;' : '';


*6395 is the topic ID,changeable....
___________

Then down below
Code (look for) Select
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['firstSubject'] . '</a>'

change it to to...
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0" style="color: '. $color. '; '. $weight .'">' . $row['firstSubject'] . '</a>'



Credits : Kender , JohnyB
Title: Re: Any chance to change the "topic title color" ?!?
Post by: Spaceman-Spiff on March 28, 2008, 04:44:55 PM
If you mark it as a sticky topic, you can change the CSS for .windowbg_sticky to show it red. Otherwise, I don't think there's a way to do it.
Title: Re: Any chance to change the "topic title color" ?!?
Post by: ccbtimewiz on March 28, 2008, 05:11:57 PM
It's quite possible. Make it so that only admins can use BBcode or HTML in their post titles.
Title: Re: Any chance to change the "topic title color" ?!?
Post by: kyle007 on March 28, 2008, 05:34:52 PM
@Spaceman-Spiff ; it's true but,i just want to change one topic's color...


@ccbtimewiz  ; i didn't understand  what you said,pls can u explain it?
Title: Re: Any chance to change the "topic title color" ?!?
Post by: Eliana Tamerin on March 28, 2008, 05:53:53 PM
ccbtimewiz, that will cause bbc and html characters in the page title, which won't render properly.
Title: Re: Any chance to change the "topic title color" ?!?
Post by: Bulakbol on March 28, 2008, 05:57:36 PM
There's a way to make all topics color red.  :)
Title: Re: Any chance to change the "topic title color" ?!?
Post by: ccbtimewiz on March 28, 2008, 07:05:07 PM
Quote from: Eliana Tamerin on March 28, 2008, 05:53:53 PM
ccbtimewiz, that will cause bbc and html characters in the page title, which won't render properly.

Simply strip HTML tags in the page title.

strip_tags($context['page_title'])
Title: Re: Any chance to change the "topic title color" ?!?
Post by: Eliana Tamerin on March 28, 2008, 08:37:03 PM
Allowing HTML tags opens up security and layout destruction possibilities. BBC would be much safer, though I'm not sure there's a strip BBC function.
Title: Re: Any chance to change the "topic title color" ?!?
Post by: ccbtimewiz on March 28, 2008, 09:13:12 PM
...

You would obviously use BBcode in the title. Then when it converts into the title, it would obviously be HTML seeing how BBcode transgorates into HTML. At that point, you would strip the HTML.

There's no difference.
Title: Re: Any chance to change the "topic title color" ?!?
Post by: Bulakbol on March 28, 2008, 10:00:37 PM
Back to the topic.  :P

The MessageIndex.template.php refers to the topic link so you can't change the color from there. You have to change the color in the Source file. And if you are willing to edit your MessageIndex.php, here's my solution.

Code (find) Select
// 'Print' the topic info.

and above it, add
$color = $row['ID_TOPIC'] == '122' ? 'red' : '';

The number '122' is the topic id number. Change it with your topic id and change the color.

Then down below
Code (look for) Select
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['firstSubject'] . '</a>'


and replace with
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0" style="color: '. $color. ';">' . $row['firstSubject'] . '</a>'
Title: Re: Any chance to change the "topic title color" ?!?
Post by: kyle007 on March 29, 2008, 04:27:20 AM
@JohnyB ;

thx,i think it's the solution,but i could't find "// 'Print' the topic info." in MessageIndex.template.php, i use a different theme,couldn't find it even in the default theme... :S

Also the other codes started with "'link' => '<a href="'......."

?
Title: Re: Any chance to change the "topic title color" ?!?
Post by: Bulakbol on March 29, 2008, 04:41:35 AM
Sorry if my message confused you but if you will read it again, you'll find out that I was talking about Sources/MessageIndex.php and not the template. The file you have to edit is Sources/MessageIndex.php and you can find it in the Sources folder.
Title: Re: Any chance to change the "topic title color" ?!?
Post by: kyle007 on March 29, 2008, 05:04:46 AM
OMG Thx so much JohnyB , it really works...Thx...

Sorry but a little que, can i make that topic also "bold" ?
Title: Re: Any chance to change the "topic title color" ?!?
Post by: Kender on March 29, 2008, 05:21:15 AM
style="color: '. $color. '; font-weight: bold;">


just a snip of what you have already changed with the edit to make it bold
Title: Re: Any chance to change the "topic title color" ?!?
Post by: kyle007 on March 29, 2008, 05:28:22 AM
Ops, all the topics became bold with both of yours way.....  :o

Title: Re: Any chance to change the "topic title color" ?!?
Post by: Bulakbol on March 29, 2008, 05:29:46 AM
If you don't like Kender's way, then we have to change our codes.

Replace the
$color = $row['ID_TOPIC'] == '122' ? 'red' : '';

with
if ($row['ID_TOPIC'] == '122')
$link = '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0" style="color: red; font-weight: bold;">' . $row['firstSubject'] . '</a>';
else
$link = '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['firstSubject'] . '</a>';


and the
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0" style="color: '. $color. ';">' . $row['firstSubject'] . '</a>'

with
'link' => $link,
Title: Re: Any chance to change the "topic title color" ?!?
Post by: Kender on March 29, 2008, 05:36:10 AM
$weight = $row['ID_TOPIC'] == '122' ? 'font-weight: bold;' : '';


'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0" style="color: '. $color. '; '. $weight .'">' . $row['firstSubject'] . '</a>'

Title: Re: Any chance to change the "topic title color" ?!?
Post by: kyle007 on March 29, 2008, 05:43:04 AM
Kender thx but what should i put between the color and bold codes ?

$color = $row['ID_TOPIC'] == '6395'  ? 'red' : '' ? 'font-weight: bold;' : '';
Title: Re: Any chance to change the "topic title color" ?!?
Post by: Kender on March 29, 2008, 05:44:27 AM
reread my message

you would put my first line of text above or below the $color =

then you would modify the link text to read what i wrote in my second line


$color = $row['ID_TOPIC'] == '6395' ? 'red' : '';
$weight = $row['ID_TOPIC'] == '6395' ? 'font-weight: bold;' : '';


then change the link to...
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0" style="color: '. $color. '; '. $weight .'">' . $row['firstSubject'] . '</a>'

Title: Re: Any chance to change the "topic title color" ?!?
Post by: Bulakbol on March 29, 2008, 05:44:38 AM
Sorry, I was editing my message when you replied. You now have choice.  :D
Title: Re: Any chance to change the "topic title color" ?!?
Post by: kyle007 on March 29, 2008, 05:48:44 AM
Kender & JohnyB , thx so much...

Sorry i'm a nooby :D But i manage at last :p

Thx again,i think it comes in handy for everyone.....
Title: Re: Any chance to change the "topic title color" ?!?
Post by: Kender on March 29, 2008, 05:49:35 AM
thats what a "community" does, is help eachother
Title: Re: Any chance to change the "topic title color" ?!?
Post by: Bulakbol on March 29, 2008, 05:52:25 AM
Thanks Kender. Help is very much appreciated.
Title: Re: Any chance to change the "topic title color" ?!?
Post by: kyle007 on March 29, 2008, 06:09:38 AM
I add the solution in my first post for everyone... ;)

Changed the icon so :=)
Title: Re: Any chance to change the "topic title color" ?!?
Post by: Bulakbol on March 29, 2008, 06:14:04 AM
You forgot to edit the message icon. Change it to "solved".  ;)
Title: Re: Any chance to change the "topic title color" ?!?
Post by: Eliana Tamerin on March 29, 2008, 11:56:32 AM
I was just thinking about this, not that you need to do so, but more information.

If you chose JohnyB's solution and want to include more topics, you can always change the line
if ($row['ID_TOPIC'] == '122')
to
if ($row['ID_TOPIC'] == '122' || $row['ID_TOPIC'] == 'xxx')

replacing xxx with any topic ID you want. Add additional topics by just expanding the code by one more || $row['ID_TOPIC'] == 'xxx' line.

Not sure if that would work for Kendar's solution, but it might if you did this:

$color = $row['ID_TOPIC'] == '6395' ? 'red' : '';
$weight = $row['ID_TOPIC'] == '6395' ? 'font-weight: bold;' : '';

to
$color = $row['ID_TOPIC'] == '6395' || $row['ID_TOPIC'] == 'xxx' ? 'red' : '';
$weight = $row['ID_TOPIC'] == '6395' || $row['ID_TOPIC'] == 'xxx' ? 'font-weight: bold;' : '';
Title: Re: Any chance to change the "topic title color" ?!?
Post by: Don Pepito on April 07, 2008, 05:59:02 AM
How can i find out ID_TOPIC?
TNX.
Title: Re: Any chance to change the "topic title color" ?!?
Post by: Bulakbol on April 07, 2008, 07:12:01 PM
Quote from: Don Pepito on April 07, 2008, 05:59:02 AM
How can i find out ID_TOPIC?
TNX.

Do you mean the id number of a topic? Hover your mouse over the topic title and the id number will show up in your browser's progress bar. It's in the bottom of your browser, something like this.

http://..../.../index.php?topic=116.0

The 116 is the topic id.
Title: Re: Any chance to change the "topic title color" ?!?
Post by: Don Pepito on April 09, 2008, 05:55:22 AM
Tanks a lot...