News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

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

Xarcell

Quote from: IchBin™ on August 22, 2010, 06:31:47 PM
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.

I'm trying to understand what your saying, but I don't. I tried googling, but that didn't help either. Your not talking about the css, right?

If your talking about the quick modify form tags, they were already outside the function.

Can you give me an example of what a style is?

Xarcell

Ok, I figured out why I could not quick modify post. It was the topic rating code I added to it.

What I done to add the topic rating was I took this code:

       echo '
<div class="cat_bar">
<h3 class="catbg">
<img src="', $message['icon_url'] . '" alt="" border="0" style="margin-top: 8px" />
<span id="author">( ', $context['num_views'], ' ) Times This Article Has Been Read - ';

// How about... even... remove it entirely?!
if ($message['can_remove'])
echo '
[ <a href="', $scripturl, '?action=deletemsg;topic=', $context['current_topic'], '.', $context['start'], ';msg=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', $txt['remove_message'], '?\');">', $txt['remove'], '</a> ]</span>
</h3>

</div>';


and applied the topic rating and got this:
       echo '
<div class="cat_bar">
<h3 class="catbg">
<img src="', $message['icon_url'] . '" alt="" border="0" style="margin-top: 8px" />
<span id="author">( ', $context['num_views'], ' ) Times This Article Has Been Read - ';

// How about... even... remove it entirely?!
if ($message['can_remove'])
echo '
[ <a href="', $scripturl, '?action=deletemsg;topic=', $context['current_topic'], '.', $context['start'], ';msg=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', $txt['remove_message'], '?\');">', $txt['remove'], '</a> ]', (!empty($modSettings['rateTopic_allow']) && !empty($context['rating_average'])) ?  ' - with ( '.$context['rating_number'].' ) votes &nbsp;<span class="inline-rating"><ul class="star-rating"><li class="current-rating" style="width: '.($context['rating_average'] / 5 * 100).'%"></li></ul></span>' : '' , '</span>';

//Topic Rating
if( !empty($modSettings['rateTopic_allow']) && !empty($context['rateTopic_board_enable']) && !$context['user']['is_guest'] ){
echo '
<form action="', $scripturl, '?action=rate" method="post" name="topicRating" accept-charset="', $context['character_set'], '">
<div class="smalltext" style="width:25%; float:right; text-align:right;">';
if ( $context['topic_starter_id'] == $context['user']['id'] )
echo '
<span class="inline-rating">'.
$txt['cant_rate_article'].
'</span>';

else {
if ( $context['user_can_rate'] == 1 && $context['topic_starter_id'] != $context['user']['id'] )
echo '
', (!empty($modSettings['rateTopic_allow']) && !empty($context['user_rating'])) ? $txt['rate_article_again'] : $txt['rate_article'], '
<span class="inline-rating" style="padding-bottom: 3px;">
<ul class="star-rating">
<li class="current-rating" id="current-rating" style="width: '.($context['user_rating'] / 5 * 100).'%"></li>
<li><a href="javascript:RateThatTopic(1)" class="one-star"></a></li>
<li><a href="javascript:RateThatTopic(2)" class="two-stars"></a></li>
<li><a href="javascript:RateThatTopic(3)" class="three-stars"></a></li>
<li><a href="javascript:RateThatTopic(4)" class="four-stars"></a></li>
<li><a href="javascript:RateThatTopic(5)" class="five-stars"></a></li>
</ul>
</span>';

else
echo '
<span class="inline-rating">'.
$txt['rateTopic_please_wait'].
'</span>';
}

echo '
<input type="hidden" name="topic" value="', $context['current_topic'], '" />
<input type="hidden" name="board" value="', $context['current_board'], '" />
<input type="hidden" name="rate" id="rate" value="" />
</div>
<script>
function RateThatTopic(value){
document.getElementById("rate").value = value;
document.topicRating.submit();
}
</script>
</form>';
}
echo '</span>
</h3>

</div>';


I have no idea if that was correct. Originally(in default template) it was supposed to be this:

Find:
<span id="top_subject">', $txt['topic'], ': ', $context['subject'], ' &nbsp;(', $txt['read'], ' ', $context['num_views'], ' ', $txt['times'], ')</span>

Replace with:
<span id="top_subject">', $txt['topic'], ': ', $context['subject'], ' &nbsp;(', $txt['read'], ' ', $context['num_views'], ' ', $txt['times'], '', (!empty($modSettings['rateTopic_allow']) && !empty($context['rating_average'])) ?  ' - '.$context['rating_number'].' votes)&nbsp;<span class="inline-rating"><ul class="star-rating"><li class="current-rating" style="width: '.($context['rating_average'] / 5 * 100).'%"></li></ul></span>' : ')' , '</span>';
//Topic Rating
if( !empty($modSettings['rateTopic_allow']) && !empty($context['rateTopic_board_enable']) && !$context['user']['is_guest'] ){
echo '
<form action="', $scripturl, '?action=rate" method="post" name="topicRating" accept-charset="', $context['character_set'], '">
<div class="smalltext" style=";width:25%;float:right;text-align:right;">';
if ( $context['topic_starter_id'] == $context['user']['id'] )
echo '
<span class="inline-rating">'.
$txt['rateTopic_topic_author_cant_rate'].
'</span>';
else {
if ( $context['user_can_rate'] == 1 && $context['topic_starter_id'] != $context['user']['id'] )
echo '
', (!empty($modSettings['rateTopic_allow']) && !empty($context['user_rating'])) ? $txt['rateTopic_Again'] : $txt['rateTopic_New'], '
<span class="inline-rating">
<ul class="star-rating">
<li class="current-rating" id="current-rating" style="width: '.($context['user_rating'] / 5 * 100).'%"></li>
<li><a href="javascript:RateThatTopic(1)" class="one-star"></a></li>
<li><a href="javascript:RateThatTopic(2)" class="two-stars"></a></li>
<li><a href="javascript:RateThatTopic(3)" class="three-stars"></a></li>
<li><a href="javascript:RateThatTopic(4)" class="four-stars"></a></li>
<li><a href="javascript:RateThatTopic(5)" class="five-stars"></a></li>
</ul>
</span>';
else
echo '
<span class="inline-rating">'.
$txt['rateTopic_please_wait'].
'</span>';
}
echo '
<input type="hidden" name="topic" value="', $context['current_topic'], '" />
<input type="hidden" name="board" value="', $context['current_board'], '" />
<input type="hidden" name="rate" id="rate" value="" />
</div>
<script>
function RateThatTopic(value){
document.getElementById("rate").value = value;
document.topicRating.submit();
}
</script>
</form>';
}
echo '


I reckon I screwed it up trying to modify it to fit my custom display.template code. Any ideas where it went wrong?

IchBin™

Quote from: Xarcell on August 23, 2010, 06:44:44 AM
Quote from: IchBin™ on August 22, 2010, 06:31:47 PM
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.

I'm trying to understand what your saying, but I don't. I tried googling, but that didn't help either. Your not talking about the css, right?

If your talking about the quick modify form tags, they were already outside the function.

Can you give me an example of what a style is?

I'm talking about the code you have inserted at the very top of the file. Sorry I didn't explain better. You've put code outside the template functions, I'm not sure what that will do, just figured it could cause problems.

I don't know anything about that mod, but if you're having problems with it I'll have to take a moment to install the mod and see how it works and where it puts things.
IchBin™        TinyPortal

Xarcell

The code outside the template function shouldn't cause any problems, especially the css. While it's not proper, browsers will still read it.

I have installed it and looked at the code and how it works. Submit wil not work. Niether will the pol if I move it below the article, but above comments. If you haven't looked at it, you can see it in action HERE. be warned though, I make changes live, so it may be working one sec, and down another. Just wait a minute or so and it'll be back up.

Thanks for your help.

nend

Quote from: Xarcell on August 23, 2010, 07:46:03 PM
The code outside the template function shouldn't cause any problems, especially the css. While it's not proper, browsers will still read it.

I have installed it and looked at the code and how it works. Submit wil not work. Niether will the pol if I move it below the article, but above comments. If you haven't looked at it, you can see it in action HERE. be warned though, I make changes live, so it may be working one sec, and down another. Just wait a minute or so and it'll be back up.

Thanks for your help.

I don't see much of anything right now, I would like to see your idea at work. I have thought about doing what your doing in the past but I haven't thought of a appropriate layout.

KensonPlays

for me, i want the first post user's profile info to be on the top, rest on left side. how to do this?

Owner of Mesozoic Haven

nend

Quote from: Kcmartz on August 24, 2010, 02:16:53 AM
for me, i want the first post user's profile info to be on the top, rest on left side. how to do this?
The code has been worked out so forth. The basic concept is there for you to miss around with, just takes a little of CSS and HTML. I am more than sure you can handle it.

Xarcell

I just noticed that nothing is showing for guests. Give me time to track down why...

Xarcell

Oh man, I think it's because of this:       if ($context['topic_first_message'] == $message['id'])      to make first post different from replies. When I revert back to the original code it shows up. Any idea on how to fix this?

Xarcell

Quote from: nend on August 23, 2010, 10:28:05 PM
Quote from: Xarcell on August 23, 2010, 07:46:03 PM
The code outside the template function shouldn't cause any problems, especially the css. While it's not proper, browsers will still read it.

I have installed it and looked at the code and how it works. Submit wil not work. Niether will the pol if I move it below the article, but above comments. If you haven't looked at it, you can see it in action HERE. be warned though, I make changes live, so it may be working one sec, and down another. Just wait a minute or so and it'll be back up.

Thanks for your help.

I don't see much of anything right now, I would like to see your idea at work. I have thought about doing what your doing in the past but I haven't thought of a appropriate layout.

Here is a test account you can use to sign and see it. Right now it doesn't want to show for guest and I'm unsure as to why.

Username: Browser
Password: smf20rc3

MultiformeIngegno

RockCiclopedia (wiki - forum), Tutta la storia del rock, scritta da voi ...
Rimanere aggiornati sul mondo della musica grazie al nuovo feed "RockCiclopedia Music News"!

Xarcell

Quote from: MultiformeIngegno on August 28, 2010, 09:50:18 AM
any news on this..?

Every works nicely, but I was unable to get anything to show up for guests.

IchBin™

It must be something else conflicting or something. I have put the change in my Display.template file. Whether I'm logged in as a guest or a user I see the same thing.
IchBin™        TinyPortal

Xarcell

Quote from: IchBin™ on August 30, 2010, 10:35:03 AM
It must be something else conflicting or something. I have put the change in my Display.template file. Whether I'm logged in as a guest or a user I see the same thing.

Weird, I tried every I knew to try, and guests could not see. I have hired someone to take a look at it, but I haven't heard back from them.

nend

Still nothing? Well if it doesn't work out just give me a PM and I can take a look for you. However I will not be available to look at it until Thursday. Sorry, just lack of time due to work.

NHWD

Quote from: Xarcell on August 20, 2010, 08:37:16 PM
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';
}

thanks for this.. i needed for something i was working on

Xarcell

Quote from: CL0WNER on April 17, 2011, 06:00:59 AM
Quote from: Xarcell on August 20, 2010, 08:37:16 PM
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';
}

thanks for this.. i needed for something i was working on


There is issues with that. I ended up having to hire someone...

NHWD

Quote from: Xarcell on April 17, 2011, 12:58:01 PM
Quote from: CL0WNER on April 17, 2011, 06:00:59 AM
Quote from: Xarcell on August 20, 2010, 08:37:16 PM
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';
}

thanks for this.. i needed for something i was working on


There is issues with that. I ended up having to hire someone...
what issues are they?

live627

The code won't execute as intended. $message['id'] isn't a boolean.

Advertisement: