Recent Topics

1 Dec 31, 2009 19:14    

My b2evolution Version: Not Entered

Hi,

I have a Twitter link I am trying to add at the end of every post, and for the most part it works great. It adds the title and perm url to Twitter.

I noticed however that when there are quotation marks used in the title of a particular blog post, the twitter update shows only everything before the quotation marks. Worst part is it leaves out the url.

Here is the code excerpt:

 <a id="tweet" target="_blank"  href="http://twitter.com/home?status=<?php urlencode($Item->title(array( 'link_type' => 'linkto_url',)) . " " . $Item->permanent_url() ); ?>"
></a>

I am thinking that maybe I need to escape any quotation marks that may be present in the blog post title??

If so, can someone kindly assist me in editing the above code?

Thanks and Happy & Healthy New Year!

-Vic

2 Dec 31, 2009 21:01

You can get escaped title with

format_to_output( $Item->title, 'htmlattr' )

This should work

<a id="tweet" target="_blank" href="http://twitter.com/home?status=<?php echo urlencode( format_to_output( $Item->title, 'htmlattr' ).' '.$Item->get_permanent_url() ); ?>@yourname"></a> 

3 Dec 31, 2009 22:17

Thanks sam2kb!

I managed to get str_replace to work as well, but your solution is much better.

Much appreciated :)

I have a new issue where twitter doesn't accept some updates because various titles are long and exceed the allotted character count when combined with the url.

4 Dec 31, 2009 23:00

If you're using b2evo 3.3 you can try this

$content = strmaxlen( format_to_output( $Item->title, 'htmlattr' ).' '.$Item->get_permanent_url(), 135 );

If you are still on b2evo 2 use this

$content = substr( format_to_output( $Item->title, 'htmlattr' ).' '.$Item->get_permanent_url(), 0, 135 );

<a id="tweet" target="_blank" href="http://twitter.com/home?status=<?php echo urlencode( $content ); ?>@yourname"></a>

You can save some space for content by using short pemalinks like
yourblog.com?p=222 where 222 is post ID

e.g.

$content = strmaxlen( format_to_output( $Item->title, 'htmlattr' ).' '.url_add_param( $Blog->gen_blogurl(), 'p='.$Item->ID ), 135 );

Not tested, use at your own risk ;)

5 Jan 01, 2010 14:39

Thanks again, I will test these out. (I am on b2evo 3.3.2)


Form is loading...