![]() |
|
|||||||
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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!’;
}
Last edited by stevetolley; 08-19-2011 at 11:04 AM. Reason: Additions |
|
#2
|
||||
|
||||
|
Quote:
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) |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
||||
|
||||
|
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" />
__________________
Casts: twitch.tv/bgeorge - Twitch Support: help.twitch.tv Recommend broadcasting software - obsproject.com (Free, works on TTV and JTV) |
|
#5
|
|||
|
|||
|
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(); ?>"/> Thanks for your help so far! |
|
#6
|
||||
|
||||
|
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="> 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. |
|
#7
|
|||
|
|||
|
How come?
The widget is its own php file called "widget-streams.php" which it uses to display the widget |
|
#8
|
||||
|
||||
|
Quote:
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) |
|
#9
|
|||
|
|||
|
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>
|
|
#10
|
|||
|
|||
|
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>
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|