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="<?php the_permalink() ?>"> <?php the_title(); ?></a></h2> <div class="Time_Category"><?php the_time('j M Y') ?>  |  <?php the_category(', '); ?></div> <div class="riassunto_content"><?php the_excerpt(); ?></div> <a href="<?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!
- The topic ‘Call a slug category by current page’ is closed to new replies.