vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Conditional for "length" (fx. number of words) for post? (https://vborg.vbsupport.ru/showthread.php?t=234166)

KrisP 01-25-2010 09:00 PM

Conditional for "length" (fx. number of words) for post?
 
I need a conditional for "length" (pref. number of words, or possibly fx. number of lines or size in KB) for a post. Is that possible :confused:

Marvin Hlavac 09-15-2011 09:16 AM

I'd love to know this, too. I place a unit of AdSense after first post, but if the first post is too short, I'd like to place the ad after the second post, so I'm looking for a conditional that would be able to recognize the post size.

kh99 09-15-2011 02:48 PM

There isn't an existing conditional for that. You'd need to create a plugin, because even if there was a way to check the message length in a template conditional, you'd still need to know if the ad had been displayed yet or not.

I haven't tested this at all, but you could try this (using hook location postbit_display_complete)

PHP Code:

$cutoff_length 10;
if (!
$adsense_displayed && (build_message_plain($post['message']) >= $cutoff_length))
{
    
$show['adsense'] = true;
    
$adsense_displayed true;
}
else
    
$show['adsense'] = false

(of course you'd change the 10 to whatever you want).


Then in postbit,
Code:

<vb:if condition="$show[adsense]">
(existing code)
</vb:if>


Marvin Hlavac 09-15-2011 03:34 PM

Hi kh99,

I much appreciate you taking the time for this. I'm going to play with it a bit.

kh99 09-15-2011 03:40 PM

I thought of a couple other things - you don't say what you'd want if the second (or third or fourth, etc) were also short. What I wrote will not display the ad until a post is long enough. Also, I forgot that it won't display at all if all the messages are short, so you need some check for that.

Marvin Hlavac 09-15-2011 04:46 PM

I display one unit of AdSense per showthread page, right bellow the first post on each page. My original intention was to move the position of the ad to bellow the second post if the first post was too short. However, in the process of trying to figure out how to achieve it, I have changed my mind a bit. Instead of doing the above, I decided to not display ads at all on pages with fewer than three posts. I have managed to achieve this. I will leave it as is for now. Should the income drop considerably, I will revisit my original plan.


All times are GMT. The time now is 06:57 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03087 seconds
  • Memory Usage 1,722KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete