KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache
System : Linux cs317.bluehost.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User : andertr9 ( 1047)
PHP Version : 8.2.18
Disable Function : NONE
Directory :  /home1/andertr9/www/wp-content/themes/ssp-starter/includes/shortcodes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home1/andertr9/www/wp-content/themes/ssp-starter/includes/shortcodes/related-posts.php
<?php

if ( ! function_exists( 'ssp_starter_shortcode_related_posts' )) {
  
  function ssp_starter_shortcode_related_posts( $atts , $content = null ) {
    extract( shortcode_atts( array(
			'count' => 4 ,
			'theme' => 'default'
    ) , $atts ));
    
		global $wpdb;
		
		$relatedposts = array( get_the_ID( ));

		$tags 	   = array( );
		$poststags = wp_get_post_tags( get_the_ID( ));
		
		foreach( $poststags AS $tag ) {
			array_push( $tags , $tag->term_id );
		}
		
		$categories 		= array( );
		$postcategories = get_the_category( get_the_ID( ));
		
		foreach( $postcategories AS $category ) {
			array_push( $categories , $category->cat_ID );
		}
		
		$posts = new WP_Query( array(
			'tag__in'				 => $tags,
			'post__not_in'	 => $relatedposts,
			'posts_per_page' => $count
		));		
		
		$related  = '';
		$related .= '<div class="related-posts ' . $theme . '">';
		$related .= '<ul>';

		while( $posts->have_posts( )) {
			$posts->the_post( );
			$related .= '<li>';
			if ( $theme == 'default' ) {
				$related .= '<a href="' . get_the_permalink( ) . '">';
				$related .= get_the_title( );
				$related .= '</a>';
			} else {
				$related .= '<a href="' . get_the_permalink( ) . '" class="post-thumbnail">';
				if ( has_post_thumbnail( )) {				
					$related .= get_the_post_thumbnail( get_the_ID( ) , 'blog' , array( 'alt' => $title ));
				} else {
					$related .= '<img width="125" height="125" src="' . get_template_directory_uri( ) . '/css/images/need-photo.jpg" class="attachment-blog size-blog wp-post-image" alt="">';
				}
				$related .= '</a>';
				$related  .= '<div class="post-categories">';
				foreach( $postcategories AS $category ) {
					$related .= '<a href="' . get_category_link( $category->cat_ID ) . '">';
					$related .= $category->name;
					$related .= '</a>';
				}
				$related .= '</div>';
				$related  .= '<div class="post-title">';
				$related .= '<a href="' . get_the_permalink( ) . '">';
				$related .= get_the_title( );
				$related .= '</a>';
				$related .= '</div>';
			}
			$related .= '</li>';
			array_push( $relatedposts , get_the_ID( ));
		}
		
		if ( $posts->found_posts < $count ) {

			$count = $count - $posts->found_posts;
			wp_reset_query( );

			$posts = new WP_Query( array(
				'category__in'	 => $tags,
				'post__not_in'	 => $relatedposts,
				'posts_per_page' => $count
			));
				
			while( $posts->have_posts( )) {
				$posts->the_post( );
				$related .= '<li>';
				if ( $theme == 'default' ) {
					$related .= '<a href="' . get_the_permalink( ) . '">';
					$related .= get_the_title( );
					$related .= '</a>';					
				} else {
					$related .= '<a href="' . get_the_permalink( ) . '" class="post-thumbnail">';
					if ( has_post_thumbnail( )) {				
						$related .= get_the_post_thumbnail( get_the_ID( ) , 'blog' , array( 'alt' => $title ));
					} else {
						$related .= '<img width="125" height="125" src="' . get_template_directory_uri( ) . '/css/images/need-photo.jpg" class="attachment-blog size-blog wp-post-image" alt="">';
					}
					$related .= '</a>';
					$related  .= '<div class="post-categories">';
					foreach( $postcategories AS $category ) {
						$related .= '<a href="' . get_category_link( $category->cat_ID ) . '">';
						$related .= $category->name;
						$related .= '</a>';
					}
					$related .= '</div>';
					$related  .= '<div class="post-title">';
					$related .= '<a href="' . get_the_permalink( ) . '">';
					$related .= get_the_title( );
					$related .= '</a>';
					$related .= '</div>';
				}
				$related .= '</li>';
			}
			wp_reset_query( );
		}
		
		$related .= '</ul>';
		$related .= '</div>';
		return $related;
  }
  
} add_shortcode( 'related-posts' , 'ssp_starter_shortcode_related_posts' );

Anon7 - 2021