Log in

View Full Version : Help on using conditionals based on the length of first post in a thread


Neutral Singh
11-24-2005, 08:57 AM
Hi

I am talking about only the very first post in any thread.

Suppose, I have a thread with more 1,000 characters in 'showthread' template. I want to place a conditional statement in the postbit template so that if the length of first post is less than say '500' characters then a statement is executed otherwise another.

For Example



<if condition="length of the post < 500 characters" >

Execute a statement

<else />

<if condition="length of the post < 700 characters" >

Execute a statement

<else />

Execute a statement for all posts > 700 characters.

<if/>

</if>



I am looking for that conditional statement that can perform this function.



Thanks in advance



Best Regards

Marco van Herwaarden
11-24-2005, 09:20 AM
With 'statement' you mean display a text, or execute coding? Coding can not be executed in a template.

Anyway, what you are trying to do can be done in a Plugin, not in a template, unless you want to write cstom JavaScript coding.

Neutral Singh
11-24-2005, 09:53 AM
Yes, i want to show different text messages on meeting the criteria. Is there any similar plugin available? Could not find one like this one. Thanks

merk
11-24-2005, 10:45 AM
Try putting the below into postbit_display_start


if($post['postcount'] == 1)
{
$post['text_length'] = strlen($post['message']);
}


Then, using conditionals


<if condition="$post['postcount'] == 1">
<if condition="$post['text_length'] <= 500">This message is less than or equal to 500 characters
<else />
<if condition="$post['text_length'] <= 700">so on
<else />
etc.....
</if>
</if>
</if>

Neutral Singh
11-25-2005, 04:33 AM
Its not working as desired. It is not calculating the character length of the message for showing the conditional text message.

In the postbit template i am using the following statement

<if condition="$post['text_length'] <= 500">
OUTPUT ONE

<else />
OUTPUT TWO

</if>

I have tried changing <= 500 characters to 1 and 5 or even 500000 but it produces only one output ie. OUTPUT ONE, which is not the desired result. Further guidance required, please.

Adding following code in the plugin produces 000 on the screen.
--> echo strlen($text_length);

merk
11-25-2005, 10:20 AM
Try changing the plugin to


if($post['postcount'] == 1)
{
$post['text_length'] = strlen($post['message']);
echo $post['text_length']; die;
}

It will halt script execution and noone will be able to view threads, so once you get a result revert it or disable it.

Neutral Singh
11-25-2005, 02:39 PM
The result echoed was 0

merk
11-25-2005, 08:33 PM
Ill take a look later this afternoon, 'message' is obviously wrong.

Marco van Herwaarden
11-25-2005, 09:32 PM
Maybe just add a global $post

Neutral Singh
11-26-2005, 06:06 AM
Please do it, i am counting upon you. :)

Marco van Herwaarden
11-26-2005, 06:20 AM
Try adding the following as the first line:
global $post;

Neutral Singh
11-26-2005, 07:16 AM
The result echoed was again 0

merk
11-26-2005, 10:01 AM
Because this hook is inside a datamanager, global doesnt really make any difference.

$post is also still defined, and $this->post is set as a reference to $post (passed to $dm->construct_postbit()) so using $this->post or $post should be the same thing.

Im pretty sure all that needs to happen is move the hook to postbit_display_complete, after $this->parse_bbcode() is called.

Let me know :)

Neutral Singh
11-27-2005, 02:23 AM
Im pretty sure all that needs to happen is move the hook to postbit_display_complete, after $this->parse_bbcode() is called.

And how do i do that ? :) Which file to edit.

merk
11-27-2005, 03:25 AM
Nono, just open the postbit_display_start hook that you created and change it in the dropdown to be postbit_display_complete.

Neutral Singh
11-28-2005, 04:36 AM
Oh Thanks!! it works like a charm. :) Thanks again.