When you are on a taxonomy page, you can get the parent from the term being displayed by using the following code with get_queried_object
. See get_terms
for the objects that are returned
$queried_object = get_queried_object('term');
$term = $queried_object->parent;
To get the taxonomy, you can simply just add
$tax = $queried_object->taxonomy;
below the code above. This can then be used in the code above as follows
<?php
$queried_object = get_queried_object('term');
$term_parent = $queried_object->parent;
$tax = $queried_object->taxonomy;
$args = array(
'parent' => $term_parent,
'orderby' => 'name',
);
$terms = get_terms( $tax, $args );
if ( !empty( $terms ) && !is_wp_error( $terms ) ){
foreach ( $terms as $term ) {
echo '<a href="' . get_category_link( $term ) . '">' . $term->name . '</a><br/>';
}
}
?>
The code above can be used either above or below the loop in your taxonomy-mytax-myterm.php
to display a list of terms from the term’s parent.
As for your second question, the answer is no. Archive pages are not meant to create a paginated index list of objects. They are exclusively meant to display post in that specific hierarchy, so a taxonomy archive is meant to display a paginated “list”, if you will, of posts from a specific term, not a paginated index list of terms.
To understand what is classified as archives to need to dig into core. Take a look at wp-includes/query.php#L1615
1615 if ( $this->is_post_type_archive || $this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax )
1616 $this->is_archive = true;
So from that, the following is regarded as archive pages
-
category.php
-
tag.php
-
archive.php
-
author.php
-
taxonomy.php
-
date.php
So, if you need to have a paginated index page of terms, you are going to need to stick to a page template for that purpose
For additional info, go and check the following links