Here is an example of an archive.php file in WordPress:

<?php
get_header(); // Include the header.php template

if (have_posts()) {
    while (have_posts()) {
        the_post(); // Set up the current post

        // Display the post title and content
        echo '<h2><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>';
        the_content();
    }
} else {
    echo '<p>No posts found.</p>';
}

get_sidebar(); // Include the sidebar.php template
get_footer(); // Include the footer.php template

In this example, the archive.php file is used to display a list of posts in a category, tag, or date archive. It first includes the header.php template, then checks if there are any posts to display. If there are, it loops through each post and displays the post title and content using the the_title() and the_content() functions. If no posts are found, it displays a message saying "No posts found." Finally, it includes the sidebar.php and footer.php templates.

Note that this is a simplified example and you can customize the archive.php file to fit your specific needs by adding additional code or modifying the existing code.

archivephp wordpress example

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

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