ibdesigner
2/24/2017 - 2:57 PM

Site location for DFP

Site location for DFP

<?php 

function get_site_location(){
	$site_location = "others";

	/* Location: Home */
	if ( is_home() ) {
		$site_location = "homepage";
	}
	
	/* Location: Any taxonomy archive */
	if ( is_archive() && ! is_category() ) {
		$site_location = get_query_var( 'taxonomy' );
	}

	/* Location: Any category */
	if ( is_category() ) {
		$catid = get_query_var( 'cat' );
		while ( $catid ) {
			$cat       = get_category( $catid );
			$catid     = $cat->category_parent;
			$catParent = $cat->cat_ID;
		}

		if ( $catParent > 0 ) {
			$catid = $catParent;
		}

		$category      = get_category( $catid );
		$site_location = $category->slug;
	}

	/* Location: Any article */
	if ( is_single() || is_singular() ) {

		$category = get_the_category( $post->ID );

		if ( isset( $category[0]->cat_ID ) ) {
			$site_location = $category[0]->slug;
		}
		
	}
	return $site_location ;
}
?>