Skip to content

Instantly share code, notes, and snippets.

@bologer
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bologer/2465a3694be0574fd66f to your computer and use it in GitHub Desktop.
Save bologer/2465a3694be0574fd66f to your computer and use it in GitHub Desktop.
category-wordpress.old.php
<?php
// abs path function
function url_origin($s, $use_forwarded_host = false){
$ssl = (!empty($s['HTTPS']) && $s['HTTPS'] == 'on') ? true:false;
$sp = strtolower($s['SERVER_PROTOCOL']);
$protocol = substr($sp, 0, strpos($sp, '/')) . (($ssl) ? 's' : '');
$port = $s['SERVER_PORT'];
$port = ((!$ssl && $port=='80') || ($ssl && $port=='443')) ? '' : ':'.$port;
$host = ($use_forwarded_host && isset($s['HTTP_X_FORWARDED_HOST'])) ? $s['HTTP_X_FORWARDED_HOST'] : (isset($s['HTTP_HOST']) ? $s['HTTP_HOST'] : null);
$host = isset($host) ? $host : $s['SERVER_NAME'] . $port;
return $protocol . '://' . $host;
}
function full_url($s, $use_forwarded_host=false)
{
return url_origin($s, $use_forwarded_host) . $s['REQUEST_URI'];
}
$absolute_url = full_url($_SERVER);
// end function abs path
if( !has_category( $post->ID ) ):
the_category( '', '', $post->ID );
// global $post;
$category_detail = get_the_category( $post->ID );
foreach ($category_detail as $key => $object):
if( $key != 0):
echo '
<script>
jQuery(function() {
console.log( jQuery(".post-categories") );
jQuery("a").each(function() {
if( jQuery(this).attr("href") == "'. $absolute_url .'") {
jQuery(this).addClass("active active_id_" + ' . $object->term_id . ');
}
});
});
</script>
';
//|| jQuery(this).attr("href") == "http://www.cs-client.com/?cat='. $object->term_id.'"
endif;
endforeach;
else:
echo '<center>Нет рубрик.</center>';
endif;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment