F
F
furcifer2018-02-06 22:02:12
WordPress
furcifer, 2018-02-06 22:02:12

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.
5a79fb2aeef58504585882.png
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

1 answer(s)
D
Denis Yanchevsky, 2018-02-07
@furcifer

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)) // и остальные Ваши параметры запроса
//Дальше сам цикл

I'm too lazy to retype all the code from the picture.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question