Skip Navigation

[Resuelto] Unable to assign "poster" to my videos

This support ticket is created hace 7 años, 5 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

Etiquetado: 

This topic contains 5 respuestas, has 2 mensajes.

Last updated by Branigan hace 7 años, 5 meses.

Assisted by: Nigel.

Autor
Mensajes
#454742

I am trying to render a video on my page using php in my single-video.php template

I have a custom field created:for the video file url and one for the poster I'm using the url of the post thumbnail. Here's the code I'm using:

<?php $poster_pic = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); ?>
<?php $poster = $poster_pic[0]; ?>

<?php echo(types_render_field("video-file", array("output" => "raw", "width" => "640", "autoplay" => "on", "poster" => $poster ))); ?>

2 things aren't working:

1. I'm not seeing the poster image when the video isn't playing
2. Video is not playing automatically.

Any help/advice appreciated.

Dan

#454833

Nigel
Supporter

Languages: Inglés (English ) Español (Español )

Timezone: Europe/London (GMT+01:00)

Hi Dan

I tested this both doing everything within Toolset, so using Views to create a Content Template for single posts and inserting the video via shortcode, and by directly editing the theme template files and using types_render_field to output the video, as you describe.

I found that using Views things worked as expected. There is one proviso, which is that if you use autoplay then you never see the poster, which I think makes sense. (And actually, a minor bug, in that you can set autoplay to anything and it will autoplay, including "off".)

In my case I was just using the standard WordPress post type with a Types video field (slug: my-video) and the post featured image for the poster.

So my content template looked like this:

[wpv-post-body view_template='None']

<p>Video:</p>

[types field='my-video' autoplay='on' width='600' poster='[wpv-post-featured-image size='full' output='url']'][/types]

Then I tried editing the PHP template instead, which is where I had a problem.

I edited my single.php file (I'm just using standard posts and twentysixteen) to modify the start of the Loop output like so:

		// Start the loop.
		while ( have_posts() ) : the_post();

			// Include the single post content template.
			get_template_part( 'template-parts/content', 'single' );

			// Insert the video
			$args = array(
				'autoplay'	=>	'on',
				'poster'	=>	the_post_thumbnail_url( 'full' ),
				'width'		=>	'640'
			);
			echo(types_render_field( 'my-video', $args ));

If I used output = raw as in your example it just printed the url of the video to the screen.

The above worked okay, except for the poster. If I disable autoplay (i.e. remove that argument) then the poster was not displayed, instead the url was printed above the non-autoplaying video.

That seems to be a bug, which I will discuss with colleagues now. But if you want to use autoplay then you shouldn't expect the poster to be displayed in any case, and so this bug might not affect you.

If you look through that and let me know how you get on.

#454837

Nigel
Supporter

Languages: Inglés (English ) Español (Español )

Timezone: Europe/London (GMT+01:00)

Hi Dan

I just noticed I was using "the_post_thumbnail_url" which echoes the url, hence why it is being printed to the screen.

I needed to be using "get_the_post_thumbnail_url", so the relevant code in my single.php template looks like this:

			// Insert the video
			$args = array(
				'autoplay'	=>	'on',
				'poster'	=>	get_the_post_thumbnail_url( $post->ID, 'full' ),
				'width'		=>	'640'
			);
			echo(types_render_field( 'my-video', $args ));

If I remove the autoplay argument then I get the poster correctly rendered.

#455226

Hi Nigel

Thanks so much for your really helpful and very clearly explained advice.

Based on the information you provided and some of my own Sherlock Holmes style investigation I've figured out that my issue was actually caused by a content filter in functions.php.

I'm using a plugin called CM Tooltip Glossary which creates rollover glossary tooltips in your text content. It does this by hooking into the the main wordpress the_content filter.

The only way I could get this glossary tooltip plugin to recognise "glossary" terms that were in standard custom text fields set up in Types was to run all the Types fields through the main the_content filter like this in my functions.php:

add_filter( 'wpcf_fields_value_display', 'apply_the_content' );
function apply_the_content( $value ) {
	return apply_filters( 'the_content', $value );
}

It would appear that this is affecting the way the string is parsed to the Types function that renders the video, and thus the $args parameters are not being understood.

For example I've noticed in other places where this filter has been applied that the string that's stored in a standard types text field is being warpped in <p></p> tags when it's rendered using the types_render_field function.

I'm totally aware that this has taken us away from our initial problem, but I'm wondering if there's a way I can hook into an action in the Types plugin so that this filter is only applied to certain Types fields rather than ALL of them?

Many thanks

Dan

#455340

Nigel
Supporter

Languages: Inglés (English ) Español (Español )

Timezone: Europe/London (GMT+01:00)

Hi Dan

I'll be happy to help with that, but could you please post it as a new thread?

Sorry for the inconvenience, but we try to keep to one issue per thread so that the forums are useful for other clients researching similar problems.

You are welcome to assign it to me when you post it.

#455346

Thanks Nigel, that would be great.

How do I assign it you? I don't see your name as an option when I create a new thread?

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.