Search code examples
wordpressloopsblogs

Wordpress customizing blog query


I bought a template called Magazette. At index page this theme lists latest blog articles from all categories using the loop.

if ( have_posts() ) : 
   while ( have_posts() ) : the_post();
       get_template_part( 'templates/template-parts/content-blog', 'beauty' ); //prints posts

I want to list only articles from one specific category, and no I can't use category page.

My solution was

while ( have_posts() ) : the_post();
    if(is_home() && in_category('enjoy')){
        get_template_part( 'templates/template-parts/content-blog', 'beauty' ); //print posts

This was working. But I want to list 8 posts at 1 page. With this code it's printing random number of blog articles. It's just hiding the posts from another categories but counter for blog page max articles is still increasing because of the_post().

Is there any way to fix this? I want to list only articles from specific category. It has to be 8 articles at 1 page. This is going to work only on the index page's blog part.


Solution

  • Self answer.

    query_posts('cat=113'); //select category for index page blogs!
        while ( have_posts() ) : the_post();
    

    I managed to filter the query with this code. But it takes only ID of the category not the name.