Answer the question
In order to leave comments, you need to log in
Displaying posts of a specific category on a page with a specific ID, WordPress?
Good afternoon! The topic has n -th number of pages with the same template. It is necessary to display records of certain categories on each page, different, on one page records of category 1, on the other category 3.
I think that for this you need to organize several cycles that will be located in the template.
The VP is very green, push on the right thought.
I tried to do the following, I get the page ID, then I try to create a loop, if the page ID is 591 then ...
Please help, many thanks in advance
Answer the question
In order to leave comments, you need to log in
Good afternoon.
WordPress has a category.php template for displaying category posts.
Regarding your code snippet, try replacing it
with
In general, the logic of what you want to do should look something like this:
$cat_id = 0;
switch ($post_id) {
case 591:
$cat_id = 30;
break;
case 852:
$cat_id = 40;
break;
case 87:
$cat_id = 43;
break;
}
$pc = new WP_Query(array('cat' => $cat_id)) // и остальные Ваши параметры запроса
//Дальше сам цикл
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question