M
M
Maxim Stepanov2015-10-14 19:02:23
Taxonomy
Maxim Stepanov, 2015-10-14 19:02:23

How to properly display taxonomy in Wordpress?

Hello!
I kindly ask you to help me with this issue. So that the reader understands that I am not asking such a question from scratch, I can say that I spent several days understanding the structure of forming custom taxonomy pages. I guess I've done 80% of the work and I just need to put it all together.
Here is what I want to do:
prntscr.com/8r8pdt
prntscr.com/8r8phr
prntscr.com/8r8pky
Here is the description of the problem:
I want to create an organization directory site. The organization should have about 8 fields of a different nature, so it became necessary to create a custom taxonomy. I created a custom taxonomy using a plugin. For each entry in the admin panel, I created several child categories - prntscr.com/8r758y.
So, I need to create/modify four pages to display posts and categories:
[A] directory of parent categories (main page),
[B] directory of all categories of all levels (page directory),
[C] directory of the parent category with subcategories of each sublevel (the page you get to when you click on the main parent category on the main page[A])(the individual category page),
[D] the custom post itself(the post page).
[A] Main page.
On the main page, only the parent categories of the topmost level should be displayed. Each such category should have a link to a list of subcategories (parent category directory with subcategories of each sublevel[C]).
[B] Catalog page (almost the same as the main page).
The difference is that only parent categories are displayed on the main page, while all categories are displayed in the catalog.
[C] Parent category directory.
Subcategories and sub-subcategories of the main parent category that the user clicked on from the main page should be displayed here. In addition, after each lowest sub-sub-sub-category, a list of records of the corresponding sub-sub-category should be displayed. Each sub-category and sub-sub-category should not have links, but the number of posts in each sub-category should be displayed. By clicking on the organization, we should go to the post page.
[D] the user post itself (post page).
All custom fields should be displayed in it.
It seems like a lot has been written, and it may sound impressive, but it seems to me that this is the usual output of posts with a slight modification of the categories. That is a simple task.
Here's what I did:
Link to the main page - leon-tgn.ru.
Link to the catalog - leon-tgn.ru/catalog/
Link to the entry - leon-tgn.ru/company/autotehcentr-maximum/
On the main page I displayed a list of the main categories.
Brought it out like this:

<ul>
<?php $hiterms = get_terms("company_category", array("orderby" => "slug", "parent" => 0, "hide_empty" => 0)); ?>
<?php foreach($hiterms as $key => $hiterm) : ?>
<li>
<?php $term_link = get_term_link( $hiterm ); ?>
<a href="<?php echo esc_url( $term_link ); ?>">
<span><?php echo $hiterm->name; ?></span>
</a>
</li>
<?php endforeach; ?>
</ul>

And they have links. But the links don't lead there. It seems that the category refers to itself. Although I created a taxonomy-company.php template to display the entry. And in fact it works if I see these record fields at this link - leon-tgn.ru/company/autotehcentr-maximum/. Actually for the catalog, I also created a taxonomy-company_category.php template. I linked this template to the catalog page through the admin panel. And he works too.
Here is his code:
<?php 
$args = array(
'hide_empty'     => 0,
'hierarchical'     => 1,
'taxonomy'        => 'company_category',
'walker'             => null
);
wp_list_categories( $args ); 
?>

I hope I have explained clearly. I feel that I incorrectly created templates for displaying categories and posts. But what exactly I missed, I do not know. Tell me please.
I will be very grateful to everyone.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Perin, 2015-10-14
@seoperin

Try the_permalink() for links

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question