ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Twitter Timeline — how do I add twitter @username dynamically?

June 05, 2011 8:07am

Subscribe [3]
  • #1 / Jun 05, 2011 8:07am

    gazaston

    128 posts

    This question may be related to a resolved thread.

    Hi there

    I have a site with a growing list of contributors. Each contributor has a Profile page that pulls in entries from a variety of channels using username=”{segment_3}” to limit entries to a particular author.

    I’m trying to implement the Twitter Timeline plugin, but I can’t figure out how to dynamically add a twitter @name to the code. Each contributor has a Profile channel, and I’ve created a custom field (“twitter-name”) for their Twitter @name.

    Here’s what I thought would work:

    {exp:twitter_timeline screen_name="{twitter-name}" limit="5"}
    <div class="tweet">
    <div class="date">{created_at format="%d-%m %g:%i%a"}</div>
    <div class="status">{text}</div>
    </div>
    {/exp:twitter_timeline}

    However, it doesn’t work — I imagine because the plugin doesn’t know whose {twitter-name} to pull in. Is there a way to link the two?

  • #2 / Jun 05, 2011 9:02am

    Mark Bowen

    12637 posts

    To pull in any custom profile fields, normally you would need to use the Custom Profile Fields Tag or ExpressionEngine won’t have any way of knowing what that variable relates to.

    You could possibly try placing those tags around the Twitter plugin and see if that works. You would need to supply the member ID for the custom profile fields tag if you are pulling the information back for anyone other than the person logged in.

    That said if it does indeed work then definitely check out the amount of queries that creates on your page as it might add an overhead.

    If it does add a significant overhead then you would need to either use a SQL query to get the information you want and supply that to the plugin or some PHP in the template to do the same sort of thing.

    Hope that helps a bit.

    Best wishes,

    Mark

  • #3 / Jun 05, 2011 9:05am

    gazaston

    128 posts

    Hi Mark,

    I’m not actually using the data from the member profile templates — just a standard channel/template. I guess that makes a difference?

  • #4 / Jun 05, 2011 9:09am

    Mark Bowen

    12637 posts

    Oops sorry, I misread what you were doing.

    In that case you would need the Twitter plugin to be inside a Channel Entries tag in order for the {twitter-name} variable to mean anything to it. Definitely test that out fully though as I’ve not used the Twitter Timeline plugin and so you may find problems in doing things that way. Most notably if the Twitter plugin has anything such as {count} or what not which is the same as the Channel Entries tag then you’ll find one of them won’t work and I’m fairly certain it would be the Twitter one.

    If that happens or is in fact a problem then you could try embedding a template which has the plugin in it inside the Channel Entries tag and see if that makes a difference.

    Besides that it would again either be some PHP in the template or a SQL query to get the information to pass into the plugin. Whichever you decide upon definitely check for large query usage just incase that method causes any overheads.

    Best wishes,

    Mark

  • #5 / Jun 05, 2011 9:15am

    gazaston

    128 posts

    Cheers Mark — simply wrapping it with a channel entries tag has nailed it. It’s always the simplest solutions that evade me!

  • #6 / Jun 05, 2011 9:19am

    Mark Bowen

    12637 posts

    Cheers Mark — simply wrapping it with a channel entries tag has nailed it. It’s always the simplest solutions that evade me!

    Excellent news. Glad that got it sorted for you. I’d still be tempted to turn on the template profiler just to see how many more queries this produces per page load doing things in this way as the Channel Entries tag is quite a big tag to use just for doing this sort of thing.

    If it’s not a problem with the queries though then yep stick with that method as it’s definitely the easiest.

    Best wishes,

    Mark

  • #7 / Jun 05, 2011 9:28am

    gazaston

    128 posts

    Will do — thanks again.

    EE Mods — you can tie this one off 😊

  • #8 / Jun 06, 2011 5:54am

    John Henry Donovan

    12339 posts

    Thanks Mark. Feel free to start a new thread if you have any more questions

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases