J
J
John2016-04-06 12:27:45
WordPress
John, 2016-04-06 12:27:45

Outputting posts from a specific category through its name?

I display posts by category ID like this:

<?php
                query_posts('cat=4');
                    while (have_posts()) : the_post(); ?>
                        <a href="<?php the_permalink(); ?>">
                            <div class="post-prew">
                                <img src=<?php the_post_thumbnail(); ?></img>

                                
                            </div>
                        </a>
            <?php             
                endwhile;
            ?>

How to do the same, but only through the category name?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Kozlov, 2016-04-06
Galt @Fargal_1

If you need via slug, then like this:

$slug = 'Url название категории';
$cat = get_category_by_slug($slug);
query_posts('cat='.$cat->cat_ID);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question