content-search.php 1.92 KB
<?php
/**
 * Search results partial template
 *
 * @package Understrap
 */

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

$img ="";
$imgid = get_post_thumbnail_id();
$post_type = get_post_type(get_the_ID());
$permalink = get_permalink();
$target = '';
$excerpt = get_the_excerpt();
if($post_type == 'attachment') {
	$permalink  = wp_get_attachment_url( get_the_ID());
	if ( wp_attachment_is_image(get_the_ID()) ) {
		$img = wp_get_attachment_url( get_the_ID());
	}
	$target = 'target="_blank"';
	$excerpt = get_post_meta ( get_the_ID(), 'description', true );   
}else if($post_type  == 'documents'){
	$permalink = get_post_meta( get_the_ID(), 'document_link', true ); 
	$target = 'target="_blank"';
	$excerpt = get_post_meta ( get_the_ID(), 'description', true );   
}

$term_list = array();
$terms = wp_get_post_terms( $post->ID, 'document-format');
if ( !empty( $terms ) && !is_wp_error( $terms ) ){
 
	foreach ( $terms as $term ) {
		$term_list = $term->name;

	}

}
?>

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

<a href='<?php echo $permalink; ?>' <?php echo $target; ?>  class='outside-a'>
	<?php


	if($imgid || $img):
	?>
	<div class='photo'>
		<?php 
			if($imgid) {
				$image = wp_get_attachment_image_src($imgid, 'medium');
				$image = $image[0];
			} else if($img ) {
				$image = $img;
			}
			$image_alt = get_post_meta ( $imgid, '_wp_attachment_image_alt', true );                    
			if(!$image_alt){
				$image_alt = get_the_title($imgid);
			}
			
		?>




	<img src='#' data-src="<?= $image ?>" class='lazy' alt='<?= $image_alt ?>' />
	</div>
	<?php endif; ?>	
	<div class='content'>

		<header class="entry-header">

			<h2 class="<?php echo $term_list;?>"><?= the_title() ?></h2>

		</header><!-- .entry-header -->

		<div class="entry-summary" >

		<?= str_replace("[...]Read More...", "",wp_strip_all_tags($excerpt, true)); ?>

		</div><!-- .entry-summary -->

	</div>
</a>
</article><!-- #post-## -->