Category ID from current URL nicename and show some posts name

We can use the following code to get category ID from current URL nicename:
We can use the following code to get category ID from current URL nicename:
<?php
if(is_category() || is_single()){
 $category = end(get_the_category());
 $current =$category->cat_ID;
 $current_name = $category->cat_name;
}
echo $current_name . ” has id “.$current.” and is called “.$current_name;
;
?>

And we can use the following code to show some posts under the category id also:<?php
foreach( ( get_the_category() ) as $category ) {
$the_query = new WP_Query(‘category_name=’ . $category->category_nicename . ‘&showposts=5’);
while ($the_query->have_posts()) : $the_query->the_post();
?>
   <li>
    <a href=”<?php the_permalink(); ?>” title=”<?php the_title(); ?>”><?php the_title(); ?></a>
   </li>
<?php endwhile; ?>
<?php
}
?>

King Php Science Welcome, you are from: 54.166.203.76