Greetings. There is a template that displays a certain list of records, and in the admin area there is a page to which this template is attached. Clicking on one of the list items should open a page with detailed information about it. However, I can not figure out how to implement this feature on WordPress.

That is, the list is displayed on the page with the URL: site.ru/catalog/ - the page always displays a list of records. But the list items should be located at: site.ru/catalog/product_1, site.ru/catalog/product_2, etc. .

Can someone tell me how to do this? Thank.

  • one
    Show a fragment of the template that is responsible for displaying the list. How do you get the list? How are permalinks configured in WordPress admin panel (Settings -> Permanent links)? Otherwise, it is not clear what exactly the problem. - Ponio
  • @Ponio This is how I display the list on the conditional site.ru/catalog/ page: $ posts = array_reverse (get_posts (array ("numberposts" => "999"))); foreach ($ posts as $ post) {setup_postdata ($ post); $ cat = get_the_category (); Thus, I display a list of all the necessary entries, now if on the page to click on the element "Element 1" from this list, it is necessary that I was redirected to site.ru/catalog/element_1. I have a template for outputting this element, only here is how to let the framework know that you need to display this template? - Genome
  • The URLs are Free: /% category% /% postname% / - Genome 4:39

1 answer 1

For example, on the site.ru/catalog page, a list of post headers is displayed; when you click on a post header, you are taken to the post page.

 $posts = array_reverse(get_posts( array("numberposts" => "999"))); // если вам нужны все посты, то лучше в этом параметре писать "-1" foreach ($posts as $post){ setup_postdata($post); $cat = get_the_category(); // оставила ваш код ?> <a href="<?php the_permalink(); // выводим ссылку на страницу поста ?>"> <?php the_title(); // выводит заголовок поста ?> </a> <?php } wp_reset_postdata(); // желательно сбрасывать данные глобальной переменной $post, которые были установлены с помощью функции setup_postdata 
  • Thank you for your reply. The listing of the list was implemented exactly in my case, I just didn’t completely insert the code, because I did not allow the limit of characters on the comment. Everything is clear, the list is displayed as necessary. The question is that when I click on the link, I am directed to site.ru/catalog/element_1, but I don’t have such a page. If, say, the directory page is unchanged, i.e. I created it in the admin and linked a template with this pkhp-code, then I have pages for the elements of this directory, I just don’t know how to create it so that I don’t have to create a page for each directory. - Genome
  • In other centers, routing is usually responsible for a file, such as urlrewrite.php or urls.py, or some other file where you can specify with the help of regulars, with which URLs which template to display. Those. it seems to have been done there: / catalog / $ "=>" catalog.html ", / catalog / <element_slug> =>" element.html "But I know a couple of days from the station and understand that this time The CMS is intended for blogs, and there is no need for routing here, and therefore I am interested in its implementation - Genome
  • What is a catalog in your understanding? You wrote that your link template is /%category%/%postname%/ , which means that the URL of each post contains first the category name and then the name of the post. And there is? - Ponio
  • Yes, that is right. I do not know how to explain that you understand me :). If I go to site.ru/catalog, then I open the category.php page, because I created a page with this URL in the admin area and linked this template to it, but how to create the same page for the elements? After all, if /% category% / is always the same, then in place /% postname% / everything can do anything, for example, element_1, element_2, ..., element_n. - Genome
  • To display categories, use the category.php template; do not create separate pages. For regular posts - template single-post.php . That is, there should be a file with that name in your theme folder. If not, then Wordpress searches for the file single.php . Clearly shown in the picture: codex.wordpress.org/images/1/18/Template_Hierarchy.png - Ponio