• Trialstyle98

    (@trialstyle98)


    Hey Guys,
    I would like to add videos from my Youtube channel to my blog.
    Therefore, I made an custom Post Type “Videos” and a Taxonomy called “playlist” with the help of “Types”.
    Now I want to customize the site of the single taxonomies (taxonomy-playlist.php).
    I would like to have the current Video displayed on the left side and on the right side (In the Sidebar) a list with all the content(Videos) in my playlist, like on https://gopro.com/channel/
    First I tried it with an html list, but that does not really work.
    Does anyone have better ideas how to realize this?

    Here is my current code:

    <?php get_header(); ?>
    
    	<?php do_action( 'colormag_before_body_content' ); ?>
    
    	<div id="primary">
    		<div id="content" class="clearfix">
    
    			<?php while ( have_posts() ) : the_post(); ?>
    
    				<?php
    					if (get_the_id() == $_GET['Videos']) {
    						the_title();
    						echo types_render_field( "video", array('raw' => false) );
    					}
    				?>
    
    			<?php endwhile; ?>
    
    		</div><!-- #content -->
    
    	</div><!-- #primary -->
    
    	<div id="secondary">
    		<div id="sidebar" class="clearfix">
    			<?php rewind_posts(); ?>
    
    			<form action="<?php echo $_SERVER['PHP_SELF'] ?>">
    				<select name="Videos" size="8" onchange="this.form.submit()">
    					<?php if ( have_posts() ) : the_post(); ?>
    						<option selected value="<?php get_the_id() ?>"> <?php the_post_thumbnail('playlist-video-thumbnail') ?> <?php the_title() ?></option>
    					<?php endif; ?>
    
    					<?php while ( have_posts() ) : the_post(); ?>
    						<option value="<?php get_the_id() ?>"> <?php the_post_thumbnail('playlist-video-thumbnail') ?> <?php the_title() ?></option>
    					<?php endwhile; ?>
    				</select>
    			</form>
    
    		</div>
    	</div>
    
    	<?php do_action( 'colormag_after_body_content' ); ?>
    
    <?php get_footer(); ?>

    I know, this can′t work. But I hope that you understand what I want to do and can help me.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Your intent is the video selected from the playlist would appear on the left in main content, clicking on a different video replaces the previous video with the selected video? I’m assuming yes.

    While using the term template to do this makes sense from a human standpoint, it’s not the right template from a WP standpoint. The term template should list all videos with the term in the main content. The sidebar is intended for common content not directly related to the current template.

    Not that you couldn’t force your scheme onto the template system, but it’s best to not fight the system. What would make more sense for WP is to create a single-{$post_type}.php template for this– single-videos.php, because you’re only displaying one video at a time. The playlist becomes a custom sidebar that lists video posts with that term.

    Sidebar content is normally through widgets, but a custom sidebar template does not need to use widgets at all if you prefer, or they can occur above or below the custom content. You could even make a playlist widget, but that is probably needlessly complicating things.

    single-videos.php is pretty much a standard single post template, it exists mainly to load the custom sidebar containing the playlist. The sidebar creates a WP_Query object to fetch playlist video posts and display the links using the normal loop used with custom query posts. Meaning you don’t do have_posts(), you do $query->have_posts(), etc. The permalinks for each post would naturally lead to the single-videos.php template without any special coding required. This would not be the case if you used the playlist term template.

    Thread Starter Trialstyle98

    (@trialstyle98)

    Hey bcworks! Yes, right. This is my intent.
    Thanks for the quick and detailed answer.
    Firstly, I wanted to make is as you described. But my problem is: A Video can be in more than one playlist. So how does the “single-videos.php” (for me “single-channel.php” because “Videos” is already used) know, which playlist to show?
    Thanks again!

    Moderator bcworkz

    (@bcworkz)

    Hmmm…

    What if the sidebar, when a video has more than one playlist, displays a dropdown selection for the user to select a different playlist? The current single video is available from the global $wp_query object. The playlists can be then be determined with wp_get_post_terms().

    Whichever playlist is first in the results is displayed automatically. It doesn’t really need to be a dropdown selector. For example, it could be an accordion style list, provided any particular list isn’t too long. Or a mobile nav menu style selection. Or…?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Template for Video-Playlist ( as custom post & Custom taxonomy)’ is closed to new replies.