建立文章列表页面


建了个文章目录页面.展示文章的标题.因为发现自己经常要回来找命令.这里记录一下免得升级被覆盖了.

将下面文件放入wp-content/themes/twentytwenty/templates/目录下面.新建页面的时候,可以选择的模板就会多一个Article Archive Template.

<?php
/**
 * Template Name: Article Archive Template
 * Template Post Type: post, page
 *
 * @package WordPress
 * @subpackage Twenty_Twenty
 * @since 1.0
 */

get_header();
?>

<main id="site-content" role="main">

    <?php include ( "wp-config.php" ) ; require_once (ABSPATH.'wp-blog-header.php'); global $wpdb; $sql="SELECT ID FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY ID DESC "; $myrows = $wpdb->get_results($sql);

    if ( have_posts() ) {
        while ( have_posts() ) {
            the_post();

            get_template_part( 'template-parts/content' );
        }
    }

    echo '<div class="entry-content">';
    echo ' <table class="table">';
    foreach ($myrows as $b) {
        echo ' <tr>';
        echo ' <td><a href="'.get_the_permalink($b->ID).'">'.get_the_date("Y/m/d", $b->ID).' - '.get_the_title($b->ID).'</a></td> ';
        echo ' </tr> ';
    }
    echo ' </table>';
    echo '</div>'

    ?>

</main><!-- #site-content -->

<?php get_template_part( 'template-parts/footer-menus-widgets' ); ?>

<?php get_footer(); ?>

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: