<?php

/**
 * Template part for displaying Audio Format
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package Pixel Charity Nonprofit
 */

?>

<article id="post-<?php the_ID(); ?>" <?php post_class() ?> >

	<?php
		// Get the post ID
		$pixel_charity_nonprofit_post_id = get_the_ID();

		// Check if there are audio embedded in the post content
		$pixel_charity_nonprofit_post = get_post($pixel_charity_nonprofit_post_id);
		$pixel_charity_nonprofit_content = do_shortcode(apply_filters('the_content', $pixel_charity_nonprofit_post->post_content));
		$pixel_charity_nonprofit_embeds = get_media_embedded_in_content($pixel_charity_nonprofit_content);

		if (!empty($pixel_charity_nonprofit_embeds)) {
			// Loop through embedded media and display only audio
			foreach ($pixel_charity_nonprofit_embeds as $pixel_charity_nonprofit_embed) {
				// Check if the embed code contains an audio tag or specific audio providers like SoundCloud
				if (strpos($pixel_charity_nonprofit_embed, 'audio') !== false || strpos($pixel_charity_nonprofit_embed, 'soundcloud') !== false) {
					?>
					<div class="custom-embedded-audio">
						<div class="media-container">
							<?php echo $pixel_charity_nonprofit_embed; ?>
						</div>
						<div class="media-comments">
							<?php
							// Add your comments section here
							comments_template(); // This will include the default WordPress comments template
							?>
						</div>
					</div>
					<?php
				}
			}
		}
	?>

	<div class="entry-content">
		<header class="entry-header">
			<?php 
				pixel_charity_nonprofit_entry_header();
				the_title( '<h3 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h3>' );
			?>
		</header>

		<div class="entry-meta">
			<?php pixel_charity_nonprofit_post_meta(); ?>
		</div>
		
		<div class="entry-text">
			<?php
				$pixel_charity_nonprofit_excerpt_limit = get_theme_mod('pixel_charity_nonprofit_excerpt_limit', 50);
				echo "<p>" . wp_trim_words(get_the_excerpt(), $pixel_charity_nonprofit_excerpt_limit) . "</p>";
			?>
		</div>

		<?php pixel_charity_nonprofit_edit_link(); ?>

	</div>
	
</article>