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

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


$imgid = get_post_thumbnail_id($search_posts[$i]['ID']);
$img = "";

$post_type = get_post_type(get_the_ID());
$permalink = get_permalink();
$target = '';
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"';

}
?>

<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];
				$image_alt = get_post_meta($imgid, '_wp_attachment_image_alt', TRUE);
			} else if($img ) {
				$image = $img;
				$image_alt = get_field('alt_text', $search_posts[$i]['ID']);
			}
		?>
		<img src='#' data-src="<?= $image ?>" class='lazy' alt='<?= $image_alt ?>' />
	</div>
	<?php endif; ?>	
	<div class='content'>

		<header class="entry-header">

			<h2 class="entry-title"><?= the_title() ?></h2>

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

		<div class="entry-summary" id='content'>

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

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

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