Forum

Thread tagged as: Twitter

Tweets in a block?

Hi Drew,

Is it possible to pull in x tweets from a feed into a area of a page defined in a block?

Nick Loat

Nick Loat 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you using the Twitter app?

Yes. Previously I used… (in a page template)

<?php
    perch_twitter_get_latest(array(
        'twitter_id'=>'xxxxxxxxxx',
        'type'=>'favourites',
        'count'=>8,
        'exclude_replies'=>false
    )); 
?>

However the way the site I'm working on is constructed I need to do the same thing but from within a block.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I think there's a tweet field type you can use in a block.

I've tried using it…

<perch:content id="tweet" type="tweet" label="Tweet ID" encode="false" />

Which allows me to enter the twitter ID from the tmeplate. Though I haven't actually go it to display a tweet - only the framework of the template. Also I not sure if I can say how many tweets I want it to display?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you entered the ID of a tweet?

In the input field that is generated. without the @… so minimastersgolf Directly below the input field is some bold text that says Tweet text: (not sure wht this is.)

Drew McLellan

Drew McLellan 2638 points
Perch Support

That field type is expecting the ID of a tweet rather than the name of a user account.

Oh… OK I try that.

Is it possible to get it to display the latest 5 or will it display one specific tweet?

Drew McLellan

Drew McLellan 2638 points
Perch Support

That field type displays one tweet. What are you trying to do?

Ideally I'd like to display the 5 latest tweets from the clients twitter feed. I know I can do this in a page template, but this site is a single page site with a region (set to allow multiples) and a template with 8 different content blocks to allow the client to reorder content in the page as they see fit. One of these blocks displays social media feeds from instagram and twitter. Instagram is fine but I need a way to display the last 5 or so tweets.

Duncan Revell

Duncan Revell 78 points
Registered Developer

Nick,

I haven't tried this, but I wonder if you could use perch:layout in your block template to call a PHP file that just calls the twitter_latest function to get the last 5 tweets.

Might work.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I think that'd work.

Otherwise you'd need a custom field type I think.

Many thanks I'll give that a go. I'll let you know the out come.

That's a neat trick! Pulling in the tweets perfectly, once I've styled them up nicely it'll be a perfect solution. Many thanks to both of you.