Call a slug category by current page

Hello everyone, I hope you can help me find a solution for the problem described below.

I wanted to create a page where to display the posts grouped by each single category.

So I created a “category.php” file and using the following code, I can group all the posts of the category related to the “slug” that I insert (in my case, for example, I will use the slug “my-category“).

To change the category, just act on the line ‘category_name’ => ‘my-category’, inserting the slug of the category you want to view.

<?php
$args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'category_name' => 'my-category',
    'posts_per_page' => 5,
);
$arr_posts = new WP_Query( $args );

if ( $arr_posts->have_posts() ) :

    while ( $arr_posts->have_posts() ) :
        $arr_posts->the_post();
        ?>
        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
            <?php
            if ( has_post_thumbnail() ) :
                the_post_thumbnail();
            endif;
            ?>


                    <h2><a href="https://projectdmc.org/support/topic/call-a-slug-category-by-current-page/<?php the_permalink() ?>">
    <?php the_title(); ?></a></h2>
                <div class="Time_Category"><?php the_time('j M Y') ?>&nbsp | &nbsp<?php the_category(', '); ?></div>
                <div class="riassunto_content"><?php the_excerpt(); ?></div>
                <a href="https://projectdmc.org/support/topic/call-a-slug-category-by-current-page/<?php the_permalink() ?>" class="leggi_articoli">
    Leggi di più...</a>
        </article>
        <?php
    endwhile;
endif;
?>  

Now I would like to replace the “my-category” value with something that calls the slug of the <span style=”text-decoration: underline;”>current</span> category page.

In this way, depending on the category that has been selected, the related posts will be displayed on the related page.

Can you help me achieve this result?

Thank you!

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer