How can I render a YouTube source in Drupal? The field which contains the informations contains this:
[fid] => 59
[display] => 1
[description] =>
[uid] => 1
[filename] => Retarded running giraffe
[uri] => youtube://v/Cn59jVAHLTs
[filemime] => video/youtube
[filesize] => 0
[status] => 1
[timestamp] => 1340129371
[type] => video
[rdf_mapping] => Array
Is there any way to render this information to a YouTube-Video embed code ? Something like this:
drupal_render_youtube('youtube://v/Cn59jVAHLTs');
Is there any solution to solve this without writing the hole embed code by my self ?
These will help...
How to render a Youtube thumbnail in a template in Drupal 7
http://drupal.org/project/mediaelement
Or someting like this:
<?php print render($variables['content']['field_url']['#object']->content['field_video']);?>
Related
As the title says - i have a single.php template which gets the category of the current post assigned.
$cat_post = get_the_category();
That function returns the category which is assigned to the post. After upgrading from 4.0.24 to 4.9.7 it stopped working. The only thing that comes to my mind is that the function is not supported but i haven't found something about this.
Any ideas?
you can use this
//get category
$category = get_the_category(get_the_ID());
//the above code will return an Array
Array
(
[0] => WP_Term Object
(
[term_id] => 2
[name] => video
[slug] => video
[term_group] => 0
[term_taxonomy_id] => 2
[taxonomy] => category
[description] =>
[parent] => 0
[count] => 1
[filter] => raw
[cat_ID] => 2
[category_count] => 1
[category_description] =>
[cat_name] => video
[category_nicename] => video
[category_parent] => 0
)
)
// you can access this array like this
$catID = $category[0]->term_id;
//for term id
$catName = $category[0]->name;
//for category name
I think you are trying to get a category from the current post which is the custom post type.
As per the documentation of the following function, it doesn't work for the custom post type. You can see it on the link below.
Click here to see the Code Reference
For custom post type, you can use get_the_terms() method. Here is the link of the Code Reference of the function.
This is how I can start describing this, it's a very strange error that maybe something else but this is the first symptom I have.
I have a custom template[taxonomy-location_types.php] that shows, a custom post type [locations] by it's custom taxonomy[location-types].
If you visit the home page you will see a menu editorial, travel, etc.
Now if you look here on this taxonomy page
The menu is gone, there are other queries that aren't firing but I'm focussing on this as a primary issue.
I have generated output from nav-menu-template.php like so:
if ( $menu && !is_wp_error($menu) && !isset($menu_items) )
{
write_log($menu);
$menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) );
write_log($menu_items);
}
and I get this:
[31-Aug-2017 15:27:52 UTC] WP_Term Object
(
[term_id] => 2
[name] => Header Menu
[slug] => header-menu
[term_group] => 0
[term_taxonomy_id] => 2
[taxonomy] => nav_menu
[description] =>
[parent] => 0
[count] => 6
[filter] => raw
)
[31-Aug-2017 15:27:52 UTC] Array
(
)
[31-Aug-2017 15:27:52 UTC] WP_Term Object
(
[term_id] => 3
[name] => Footer One
[slug] => footer-one
[term_group] => 0
[term_taxonomy_id] => 3
[taxonomy] => nav_menu
[description] =>
[parent] => 0
[count] => 5
[filter] => raw
)
[31-Aug-2017 15:27:52 UTC] Array
(
)
So it sees the menu but for some reason return no items in either menu.
I have turned off all plugins and still get the same result, I have also eliminated all other queries on this page to see if there was conflict and this still this happens.
Any insight on this one would be great not sure where to look next for issues.
Chalk another one up for RTFM, I had a pre_get_posts hook altering the query and I didn't ensure that the query it was altering was just the $query->is_main_query() because strangely enough this alteration was getting into the nav_menu query.
query monitor is now my new best friend.
I have a problem with my drupal page. We use the opigno tool (its a module to that allows to create course - nodes which can be bought).
Now we have a problem with the view of the course-node. Everything works fine until a user bought the course and the drupal commerce status is on "pending". The problem now is that the node is showing nothing except the title of the course.
I began to think whats going on and took a look to the view settings for the course-view. Nothing (no Permission was set, no filter criteria ...)
Then I took a look at the template override of the course-view. And then I saw smth ...
print render($content['body']);
Ah! A render function to render the content of the view. So I asked myself: What is in content ?
After printing out the $content variable I saw this:
Array
(
[body] => Array
(
[#theme] => field
[#weight] => 1
[#title] => Description
[#access] =>
[#label_display] => hidden
[#view_mode] => full
[#language] => und
[#field_name] => body
[#field_type] => text_with_summary
[#field_translatable] => 0
[#entity_type] => node
[#bundle] => course
[#object] => stdClass Object
(
[vid] => 185
[uid] => 60
[title] => Demo Course
[log] =>
[status] => 1
[comment] => 1
[promote] => 0
[sticky] => 0
[vuuid] => 16e7999b-28bb-4f3e-8bed-54a21b17f398
[nid] => 176
[type] => course
[language] => und
[created] => 1406897520
[changed] => 1407145285
[tnid] => 0
[translate] => 0
[uuid] => 22baf19a-dc32-4137-b698-89f1bb4adc59
[revision_timestamp] => 1407145285
[revision_uid] => 1
[body] => Array
(
[und] => Array
(
[0] => Array
(
[value] =>
This is a sample course for beta testers, it will show you the structure of the courses.
Here usually is displayed the description of the course.
Please "enroll" if you want to see the contents of this demo course.
[summary] => This is a sample course for beta testers to help you see the structure of a course. Please have a look on it!
[format] => html
[safe_value] =>
This is a sample course for beta testers, it will show you the structure of the courses.
Here usually is displayed the description of the course.
Please "enroll" if you want to see the contents of this demo course.
[safe_summary] => This is a sample course for beta testers to help you see the structure of a course. Please have a look on it!
)
)
)
)
Aaah! So $content has the content, but its not printed out with render()! But why ?
I searched in google for a hook which are able to "override" the render function and maybe deny the output when the user is on "pending". But... nothing.
I found this hook:
{hook}_node_view()
I searched for a using of this hook in all modules but when deleteing these functions from the modules did not changed anything. Are there other options to "override" the render() function ? Another hooks I can search for ? Or maybe you had the same problem with opigno ?
I am sorry - the problem was the Opigno Field Access Module. I deactivated it and it works like a charm.
I'm using flowplayer module to play videos on my site. I would like to add sutitles to some of the movies. How can I do it in Drupal?
I tried to add them like this:
$flowplayer = array(
'clip' => array(
'url' => str_replace('sites/default/files/videos', 'http://www.mysite.com/sites/default/files/videos', $node->field_video[0]['filepath']),
'captionURL' => str_replace('sites/default/files/videos', 'http://www.mysite.com/sites/default/files/videos', $node->field_caption[0]['filepath'])
),
....
Then the output is:
<param value="config={"clip":{"url":"http://www.mysite.com/sites/default/files/videos/video.flv","captionURL":"http://www.mysite.com/sites/default/files/videos/subtitles.srt","scaling":"fit"},...
However it says no stream found. When I erase "clip", the video is found.But how can I add subtitles?
I wonder if I need some plugin or what is wrong in my code?
Thanks.
Are you going to have more than one video? You might try using the playlist param which has support for titles. I'm not sure how you would display them (i'm doing something very similar at the moment, hopefully this is helpful). I'm using the Flowplayer API module but the js syntax should be similar.
$player = theme('flowplayer',array(
'clip' => array(
'duration' => 5,
'autoPlay' => true
),
'playlist' => array(
array('url' =>'http://localhost/episode_18.mp4','title' => 'Episode 18'),
array('url' =>'http://localhost/episode_19.mp4','title' => 'Episode 19'),
array('url' =>'http://localhost/6.jpg','title' => 'Image')
),
'plugins' => array(
'controls' => array(
'playlist' => true
)
)
)
);
return $player;
I'm using views_get_view_result to directly access the data in a view. I've stumbled upon this odd behavior where cck fields are prefixed with the first field name as a query optimization. Explained here.
What's bizarre though is that fields are named differently depending on whether I retrieve that data as Anonymous or as Admin. I'm pretty sure all my permissions are set up, and the view itself has no restrictions. What is going on here?
This is a big problem since I can't know how to retrieve a field. Here's a dump of the two view results. Notice that node_data_field_game_date_field_game_home_score_value != node_data_field_game_official_field_game_home_score_value.
// View as Admin
stdClass Object
(
[nid] => 3191
[node_data_field_game_date_field_game_date_value] => 2010-03-27T00:00:00
[node_type] => game
[node_vid] => 5039
[node_data_field_game_date_field_game_official_value] => 0
[node_node_data_field_game_home_team_title] => TeamA
[node_node_data_field_game_home_team_nid] => 3396
[node_data_field_game_date_field_game_home_score_value] => 68
[node_node_data_field_game_visitor_team_title] => TeamB
[node_node_data_field_game_visitor_team_nid] => 3442
[node_data_field_game_date_field_game_visitor_score_value] => 118
)
// View as Anonymous
stdClass Object
(
[nid] => 3191
[node_data_field_game_date_field_game_date_value] => 2010-03-27T00:00:00
[node_type] => game
[node_vid] => 5039
[node_data_field_game_official_field_game_official_value] => 0
[node_node_data_field_game_home_team_title] => TeamA
[node_node_data_field_game_home_team_nid] => 3396
[node_data_field_game_official_field_game_home_score_value] => 68
[node_node_data_field_game_visitor_team_title] => TeamB
[node_node_data_field_game_visitor_team_nid] => 3442
[node_data_field_game_official_field_game_visitor_score_value] => 118
)
Very weird behavior. Maybe it's a problem with content permission?