还有更多函数,例如:
the_title()
the_content()
the_post_thumbnail()
the_permalink()
the_excerpt()
the_time()
the_author()
the_category()
<?php /*Template Name: My Custom Page Template*/ ?> <?php get_header(); ?> <div id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <?php $args = array( 'post_type' => 'post' ); $post_query = new WP_Query($args); if($post_query->have_posts() ) { while($post_query->have_posts() ) { $post_query->the_post(); ?> <h2><?php the_title(); ?></h2> <p><?php the_content(); ?></p> <?php } } ?> </main><!-- .site-main --> </div><!-- .content-area --> <?php get_sidebar(); ?> <?php get_footer(); ?>
将此代码保存在您的模板文件中,它将在前端显示该页面上的所有文章,您可以根据您的设计布局进行设计,使其外观和感觉更好。
您还可以根据您的要求添加自己的自定义代码,并可以执行以下操作:
- 创建不同的页眉和页脚
- 根据您的 PSD/线框模板自定义布局
- 自定义侧边栏位置或可以删除
- 显示特定条件的特定文章类型
您可以在此自定义页面模板上执行更多操作。只需思考并执行您的自定义代码。
就是这样了。您已完成 WordPress 中的自定义页面模板。
好了,关于在WordPress中创建自定义页面模板方法基本就是这样,更多关于WordPress技巧请点击下面的相关文章
标签:WordPress
相关阅读 >>
wordpress thickbox 点击图片显示下一张图的修改方法
详解wordpress开发中get_header()获取头部函数的用法
在sae(sina app engine)上部署wordpress站点的教程
更多相关阅读请进入《wordpress》频道 >>