Hi,
I'm trying to use strlen to get the number of characters in the title of the post.
What is wrong with this code?
<?php
$sss = the_title();
echo strlen($sss);
?>
Thanks!
Hi,
I'm trying to use strlen to get the number of characters in the title of the post.
What is wrong with this code?
<?php
$sss = the_title();
echo strlen($sss);
?>
Thanks!
What I am trying to do is this:
I have a 300px box and when the title is short or long (with the excerpt) it changes how it look... I'd like to set something so that when the title is short, it would add a <p> or
automatically.
Is it possible?
to get the title as a string, use
get_the_title()
http://codex.wordpress.org/Template_Tags/get_the_title
or
the_title('','',false)
http://codex.wordpress.org/Template_Tags/the_title
Thanks a lot!
Next step for me is to find a way to make it work correctly and put a if command so that it will add a <p> or
when it is shorter...
I'll try to do it by myself... and I will ask if I can't... Thanks
Damn it I really am bad at PHP... What is wrong with my code?
<?php
$sss = the_title('','',false);
if (strlen($sss)<43)
{echo '<p/>';
?>Tried this as well... a failure
<?php
$sss = the_title('','',false);
$small= the_title('','<p/>');
$big = the_title();
if (strlen($sss)<43) return $small;
else return $big;
?>Anybody can help? Thanks
Now it seems to work... `<?php
$sss = the_title('','',false);
if (strlen($sss)<43) the_title('','<p/>');
else the_title();
?>
`
Thanks anyway
your code could look like this:
<?php
$sss = the_title('','',false);
$small = $sss . '<br />';
$big = $sss;
if (strlen($sss)<43) echo $small;
else echo $big;
?>
this $small= $sss . '<br />'; should add a linebreak to the string that contains the short title;
the '<p/>' is not a valid html or other code.
concatenate strings:
http://php.net/manual/en/language.operators.string.php
return will not print anything, it is for use with functions:
http://php.net/manual/en/function.return.php
use echo to output things to the screen:
http://php.net/manual/en/function.echo.php
edit: just saw your last post;
well done, your code should work.
it is actually making good use of the wordpress template tag 'the_title()'
you could just replace <p/> with <br /> to make it more valid html.
This topic has been closed to new replies.