Here is an example of a WordPress archive.php file that includes the term name and link by ID:

<?php
get_header();

// Get the current taxonomy term ID
$term_id = get_queried_object_id();

// Get the term object
$term = get_term($term_id);

// Output the term name and link
echo '<h1>' . $term->name . '</h1>';
echo '<a href="' . get_term_link($term) . '">View all ' . $term->name . '</a>';

// Start the WordPress loop
if (have_posts()) {
    while (have_posts()) {
        the_post();
        // Display post content here
    }
} else {
    echo 'No posts found.';
}

get_footer();
?>

In this example, we first get the current taxonomy term ID using get_queried_object_id(). Then, we use get_term() to retrieve the term object based on the ID.

Next, we output the term name using $term->name and create a link to view all posts in that term using get_term_link($term).

Finally, we start the WordPress loop to display the post content. If no posts are found, we display a message saying "No posts found."

Remember to customize the loop to display the desired post content.

archivephp wordpress examplei want also term name by id and link

原文地址: https://www.cveoy.top/t/topic/i5gM 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录