Go Back   Justin.tv Community Help Forums > Community Help > Help!

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-19-2011, 11:03 AM
stevetolley stevetolley is offline
Junior Member
 
Join Date: Aug 2011
Posts: 11
Default Justin TV - Showing whether or not a channel is Live (Wordpress)

I have a stream section on my website (http://www.wasdgamer.com)

And in the sidebar I have a list of streams, I would like to add whether or not the stream is onAir/offAir, I have found the following code but would like to make the channel name a variable based on the stream title. (e.g. ../streams/channelname)
(this is in Wordpress, and I can't find any one else with the same issue)

Code:
$json_file = file_get_contents(“http://api.justin.tv/api/stream/list.json?channel=ChannelName“, 0, null, null);
$json_array = json_decode($json_file, true);

if ($json_array[0]['name'] == ‘live_user_ChannelName‘) {
    echo ‘Live stream is online!’;
}
else {
    echo ‘Live stream is offline!’;
}
If you understand what I'm asking for any help would be appreciated, if not let me know and I will try to explain better :]

Last edited by stevetolley; 08-19-2011 at 11:04 AM. Reason: Additions
Reply With Quote
  #2  
Old 08-19-2011, 11:23 AM
bgeorge's Avatar
bgeorge bgeorge is offline
Twitch.tv Admin
 
Join Date: Feb 2011
Location: Pennsylvania, USA
Posts: 990
Default

Quote:
Originally Posted by stevetolley View Post
I have found the following code but would like to make the channel name a variable based on the stream title.(e.g. ../streams/channelname)
(this is in Wordpress, and I can't find any one else with the same issue)
I'm not really sure what you mean by that. Can you see if you can explain it a little differently? Do you mean when you do to "http://www.wasdgamer.com/streams/honcast/" you want to be able to set a variable to the channel name, "honcast" in this example.

If you are just looking to retrieve the channel title from the api you can do it this based upon what you already have:

Code:
$title = $json_array[0]['channel']['status'];
__________________
Casts: twitch.tv/bgeorge - Twitch Support: help.twitch.tv
Recommend broadcasting software - obsproject.com (Free, works on TTV and JTV)
Reply With Quote
  #3  
Old 08-19-2011, 11:31 AM
stevetolley stevetolley is offline
Junior Member
 
Join Date: Aug 2011
Posts: 11
Default

Basically, if you look in the sidebar, there is a widget with the channel names on, for each of those i would like it to display whether or not it is live, but I have only found a way to do it for ONE channel, not based on the multiple channels in the list, if thats any better?

An example of which is attached

Also I need it in PHP so I can place it within the Wordpress file,

P.S Thanks for the fast reply, this is really bugging me
Attached Images
File Type: jpg Example.jpg (39.0 KB, 31 views)
Reply With Quote
  #4  
Old 08-19-2011, 12:08 PM
bgeorge's Avatar
bgeorge bgeorge is offline
Twitch.tv Admin
 
Join Date: Feb 2011
Location: Pennsylvania, USA
Posts: 990
Default

Since you can't embed arbitrary PHP code inside a widget in Wordpress without writing one custom the easiest way I can think of doing this is by using a PHP script to return an image based on the whether the stream is live or not.

I wrote a quick script to return either an online or offline image based on the stream status -> http://pastie.org/2398357

Just upload that to your webserver and place an online.png and offline.png image in that same directory.

Then in the widget in Wordpress, you just need to add an image tag where you want the status to show up.

Code:
<img src = "http://path/to/script.php?stream=CHANNELNAME" />
Example: http://dev.btx.me/stevequestion/
__________________
Casts: twitch.tv/bgeorge - Twitch Support: help.twitch.tv
Recommend broadcasting software - obsproject.com (Free, works on TTV and JTV)
Reply With Quote
  #5  
Old 08-19-2011, 01:08 PM
stevetolley stevetolley is offline
Junior Member
 
Join Date: Aug 2011
Posts: 11
Default

Ok cool, if you check the website now, it recognizes the script and displays a picture, but how can I change it so it makes the channel name to match the title for instance, I tried...

Code:
<img src="http://pathto/script.php?stream=<?php the_title(); ?>"/>
To try and get it to take the title of the stream, but it didnt work?

Thanks for your help so far!
Reply With Quote
  #6  
Old 08-19-2011, 01:32 PM
bgeorge's Avatar
bgeorge bgeorge is offline
Twitch.tv Admin
 
Join Date: Feb 2011
Location: Pennsylvania, USA
Posts: 990
Default

Thats not as easy to do since you can't use direct PHP code in a widget.

Edit: Oh and make sure you include the channel name in the <img> tag. You are using
Code:
<img src="http://www.wasdgamer.com/wp-content/themes/leetpress/streamstatus.php?stream=">
and didn't put the stream name at the end.

It should be, for example:
Code:
<img src="http://www.wasdgamer.com/wp-content/themes/leetpress/streamstatus.php?stream=honecast">
__________________
Casts: twitch.tv/bgeorge - Twitch Support: help.twitch.tv
Recommend broadcasting software - obsproject.com (Free, works on TTV and JTV)

Last edited by bgeorge; 08-19-2011 at 01:36 PM.
Reply With Quote
  #7  
Old 08-19-2011, 01:34 PM
stevetolley stevetolley is offline
Junior Member
 
Join Date: Aug 2011
Posts: 11
Default

How come?

The widget is its own php file called "widget-streams.php" which it uses to display the widget
Reply With Quote
  #8  
Old 08-19-2011, 02:08 PM
bgeorge's Avatar
bgeorge bgeorge is offline
Twitch.tv Admin
 
Join Date: Feb 2011
Location: Pennsylvania, USA
Posts: 990
Default

Quote:
Originally Posted by stevetolley View Post
How come?

The widget is its own php file called "widget-streams.php" which it uses to display the widget
Oh, you actually have a custom widget for that? I was assuming that you were doing static HTML inside of one of Wordpress stock widgets.

So you want to do something like this -> http://dev.btx.me/stevequestion/ <- basically?
__________________
Casts: twitch.tv/bgeorge - Twitch Support: help.twitch.tv
Recommend broadcasting software - obsproject.com (Free, works on TTV and JTV)
Reply With Quote
  #9  
Old 08-19-2011, 02:14 PM
stevetolley stevetolley is offline
Junior Member
 
Join Date: Aug 2011
Posts: 11
Default

yes exactly, atm the code for that category is as below

Code:
					/** Get stream from cat1 **/
						
					$query2 = array('showposts' => $number, 'nopaging' => 0, 'post_status' => 'publish', 'post_type' => 'streams', 'stream_category' => $instance['cat1']);
					$loop2 = new WP_Query($query2);
					if ($loop2->have_posts()) :
						
					?>
						
					<?php  while ($loop2->have_posts()) : $loop2->the_post(); ?>
							
						<div class="side-item">
									
							<h4 class="side-review-heading"><a href="<?php echo get_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h4>
							<span class="side-item-cat"><?php echo get_the_term_list( $post->ID, 'stream_category', '',', ' ) ?></span>
							
			<img src="http://thepath.com/streamstatus.php?stream="/>
																		
						</div>
Reply With Quote
  #10  
Old 08-19-2011, 02:15 PM
stevetolley stevetolley is offline
Junior Member
 
Join Date: Aug 2011
Posts: 11
Default

yes exactly, atm the code for the first category is as below:

Code:
					/** Get stream from cat1 **/
						
					$query2 = array('showposts' => $number, 'nopaging' => 0, 'post_status' => 'publish', 'post_type' => 'streams', 'stream_category' => $instance['cat1']);
					$loop2 = new WP_Query($query2);
					if ($loop2->have_posts()) :
						
					?>
						
					<?php  while ($loop2->have_posts()) : $loop2->the_post(); ?>
							
						<div class="side-item">
									
							<h4 class="side-review-heading"><a href="<?php echo get_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h4>
							<span class="side-item-cat"><?php echo get_the_term_list( $post->ID, 'stream_category', '',', ' ) ?></span>
							
			<img src="http://www.wasdgamer.com/wp-content/themes/leetpress/streamstatus.php?stream="/>
																		
						</div>
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 01:35 AM.