Problems, need help? Have a tip or advice? Post it here.
2 posts Page 1 of 1
Hi

I am trying to make a twitter feed that I can place into cloned pages, and I would like to use this shortcode [live hastag].

I am using this great simple script by sonnyt called Tweetie https://github.com/sonnyt/Tweetie

It is working fine with this code in kfunctions.php
Code: Select all
   // 5.
   // Twitter Live
   // usage: [live]

   $FUNCS->register_shortcode( 'live', 'live_handler' );

   function live_handler( $params, $content=null ){
       global $FUNCS;
       
       extract( $FUNCS->get_named_vars(array(
           'hashtag' => ''
       ), $params) );
       
      return '
          <div class="example1"><a href="javascript:window.location.href=window.location.href">Refresh page</a>
          <div class="tweet"></div>
          </div>';
   }


Problem is that I would like to define the hashtag to look for within Couch with for example [live somehashtag]. The Tweetie script uses a javascript to fetch hashtags, it looks something like this:
Code: Select all
            <script class="source" type="text/javascript">
        $('.example1 .tweet').twittie({
            username: 'Sistestoppen',
            hashtag: 'e3sistestopp',
            dateFormat: '%b. %d, %Y',
            template: '{{tweet}} <div class="date">{{date}} <a href="{{url}}" target="_blank" style="padding-left:10px;">Link til Tweet</a><a href="https://twitter.com/Sistestoppen" target="_blank" style="padding-left:10px;">{{screen_name}}</a></div>',
            count: 100,
            hideReplies: true,
            apiPath: '/js/api/tweet.php'
        });
    </script>


At the moment I have this code outside of kfunctions.php in my template file. Because of this the shortcode will only work with one spesific hashtag, I would like to be able to use this script with whatever hashtag I want to create "live coverage". My problem is that I cant place this script code within kfunctions.php because when I do the page will just be blank. Is there any way that I could define a hashtag to look for within Couch?
Try this - replace your return statement in the live_handler function with the following -
Code: Select all
$html = <<<EOS
    <cms:set twitter_hashtag="<cms:addslashes>$hashtag</cms:addslashes>" scope='global'/>
    <div class="example1">
        <a href="javascript:window.location.href=window.location.href">Refresh page</a>
        <div class="tweet"></div>
    </div>
EOS;

return $FUNCS->embed($html, 1);
This will set the Couch variable twitter_hashtag for use later in your inline JS. Does this help?
2 posts Page 1 of 1