Is there a way to have a different layout for first post?

Started by Xarcell, August 16, 2010, 07:50:37 AM

Previous topic - Next topic

Xarcell

SMF 2.0 RC3

I've been thinking.

Is there a way to show a different layout for teh first post from it's replies?

Something like this:

If first post {
echo 'template code":
}

else 'template code';



I been thinking about modifying the display.template.php to show a different layout from the replies. Can this been done without rewriting alot of the SMF code?

live627

Code (Find in ./Themes/default/Display.template.php, at or around line 215) Select
<div class="', $message['approved'] ? ($message['alternate'] == 0 ? 'windowbg' : 'windowbg2') : 'approvebg', '">

Code (Replace with) Select
<div class="', $message['approved'] ? ($message['alternate'] == 0 ? 'windowbg' : 'windowbg2') : 'approvebg', $context['first_message'] ? 'first_post_class' : '', '">

Xarcell

Quote from: live627 on August 16, 2010, 07:33:00 PM
Code (Find in ./Themes/default/Display.template.php, at or around line 215) Select
<div class="', $message['approved'] ? ($message['alternate'] == 0 ? 'windowbg' : 'windowbg2') : 'approvebg', '">

Code (Replace with) Select
<div class="', $message['approved'] ? ($message['alternate'] == 0 ? 'windowbg' : 'windowbg2') : 'approvebg', $context['first_message'] ? 'first_post_class' : '', '">

Thanks live.

$context['first_message'] is what I was looking for. Although I don't see how that would allow me to have a different layout for first post.

In display.template.php tried this:

if ($context['first_message']){

echo 'template code';
               }

if ($context['num_replies']){

echo 'template code';
               }


But this duplicates all posts, including first post & replies. The different layout works for the first post, but also replies, but not the duplicate first post & replies.


nend

It looks like if it is the first post then it changes the class to first_post_class, which you will have to set a style for this class in your style sheets. ;)

live627

actually the class is added - the others (windowbg, approvebg) are still there

Xarcell

I need more than just a style change though. If you get any ideas let me know.

IchBin™

I think what you're looking to do will require a pretty big edit in the Display.template.php file Xarcell. Basically what you probably want to do is find this spot (read the comments too). :)

    // Get all the messages...
    while ($message = $context['get_message']())
    {


Add your if statement:

   // Get all the messages...
    while ($message = $context['get_message']())
    {
        if ($context['first_message'])  {
            echo 'what you want here';
            // I would just copy the code in this while loop and edit it into this if statement.
        }
        else {
              // Surround the rest of the code in the while function with these curly braces.
        }


It's up to you how much you customize. You'll just have to make sure you cut it off at the same points for both the if and the else statements.
IchBin™        TinyPortal

Xarcell

Quote from: IchBin™ on August 17, 2010, 07:37:01 PM
I think what you're looking to do will require a pretty big edit in the Display.template.php file Xarcell. Basically what you probably want to do is find this spot (read the comments too). :)

    // Get all the messages...
    while ($message = $context['get_message']())
    {


Add your if statement:

   // Get all the messages...
    while ($message = $context['get_message']())
    {
        if ($context['first_message'])  {
            echo 'what you want here';
            // I would just copy the code in this while loop and edit it into this if statement.
        }
        else {
              // Surround the rest of the code in the while function with these curly braces.
        }


It's up to you how much you customize. You'll just have to make sure you cut it off at the same points for both the if and the else statements.

Ya, I know it's a pretty big edit and I'm prepared to do it, and I think I'm capable. It just will take some time. I'm trying to change the display.template.php file to resemble articles/comment with a single file change. I think that's the best route to go instead of adding a mod. If I can just separate the first post from the replies with different layouts, I'll be alright. It's part of the process in learning php.

I already made a smf navbar mod(with a little help) that's facebook-like without chat, and it's shaped up nicely. I plan to release it for free soon. If you want to look at it and give me your opinion, I can PM you with the URL.

Thanks for your help Ich, I will try your solution.

Xarcell

 
   // Get all the messages...
    while ($message = $context['get_message']())
    {
        if ($context['first_message'])  {
            echo 'what you want here';
            // I would just copy the code in this while loop and edit it into this if statement.
        }
        else {
              // Surround the rest of the code in the while function with these curly braces.
        }


Doesn't seem to work. First post and replies all look the same.

IchBin™

Oops, I thought that ['first_message'] indicated true or false. It actually indicates the id of the message. Change this line:
if ($context['first_message'])  {

To this:
if ($context['first_message'] == $message['id'])  {
IchBin™        TinyPortal

Xarcell

Quote from: IchBin™ on August 18, 2010, 08:05:17 PM
Oops, I thought that ['first_message'] indicated true or false. It actually indicates the id of the message. Change this line:
if ($context['first_message'])  {

To this:
if ($context['first_message'] == $message['id'])  {

That did the trick! Thanks alot Ich. Life saver... :P

IchBin™

IchBin™        TinyPortal

Xarcell

So I've run into a problem...

Everything works fine & dandy, until you get more than one page of replies. When you view the second page of replies, the first reply is different from all the rest of the replies. First post should look like first post, and replies should look like replies...

Any ideas on how to get around this?

nend

Quote from: Xarcell on August 20, 2010, 07:53:47 AM
So I've run into a problem...

Everything works fine & dandy, until you get more than one page of replies. When you view the second page of replies, the first reply is different from all the rest of the replies. First post should look like first post, and replies should look like replies...

Any ideas on how to get around this?

I have one

$temp = explode(".", $_REQUEST['topic']);
if ($context['first_message'] == $message['id'] && $temp[1] == 0)  {


But I even see flaws with that one.

Will just dug into the source for you, it looks like the very first post is stored in $topicinfo['id_first_msg'] so this is what I would do.

if ($context['first_message'] == $topicinfo['id_first_msg'] && $context['first_message'] == $message['id']) {

Be sure to global topicinfo in your template or it will not work.

This might be easier and better.

if ($topicinfo['id_first_msg'] == $message['id']) {


Also looking further down the code I notice $topicinfo['id_ifrst_msg'] turns into $context['topic_first_message'].

So no global and code changes to
if ($context['topic_first_message'] == $message['id']) {

Xarcell

Quote from: nend on August 20, 2010, 12:16:24 PM

So no global and code changes to
if ($context['topic_first_message'] == $message['id']) {

Thanks, that did the trick!

Xarcell

I wonder if we can take this one more step.

I wonder if it's possible to also show "topic_first_message" at the topic of every page of replies? Without editing any other files.

Xarcell

For those wanting to know, this is what's being used so far:


      if ($context['topic_first_message'] == $message['id']) {

       echo 'template code';
}
       else {

       echo 'template code';
}

nend

Quote from: Xarcell on August 20, 2010, 05:53:29 PM
I wonder if we can take this one more step.

I wonder if it's possible to also show "topic_first_message" at the topic of every page of replies? Without editing any other files.

Nope not possible without editing display.php. I think though it may be possible through ssi.php, but that is sloppy and it would be much better by editing display.php.

Xarcell

Quote from: nend on August 21, 2010, 12:03:16 AM
Quote from: Xarcell on August 20, 2010, 05:53:29 PM
I wonder if we can take this one more step.

I wonder if it's possible to also show "topic_first_message" at the topic of every page of replies? Without editing any other files.


Nope not possible without editing display.php. I think though it may be possible through ssi.php, but that is sloppy and it would be much better by editing display.php.

I figured, but I reckon ATM it's not that important.

I did run into a brick wall with though. I've modified the template display.template.php to make it look like an article with comments. However quick modify(little icon thingy) does not save the edited message. Also, if I try to move the poll under the first post, same thing happens, the poll will not save. I've also added topic rating mod. Same thing happens with it, it doesn't not save.

Anyone want to look at the file and point out what I've done wrong? Attached is the file and the image is needed. Place in images/themes.

IchBin™

It's most likely because you have put the style tags outside of the function Xarcell. Looks like it's not possible to add to the $context['html_headers'] inside the template though. I would either move it to the index.template.php file, or add it to the Display.php source file. I'm betting that is the cause of the errors that you're having. Trying removing all the code before the function and see if that fixes your problems.
IchBin™        TinyPortal

Advertisement: