在WordPress中创建自定义页面模板方法详解


当前第2页 返回上一页

还有更多函数,例如:

  • 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()获取头部函数的用法

多个wordpress站点使用同一数据库的方法

wordpress中查询文章的循环loop结构及用法分析

在sae(sina app engine)上部署wordpress站点的教程

wordpress语言切换(例如中文版和英文版转换)

推荐几个好用的wordpress媒体库分类文件夹管理插件

图文讲解在bae上搭建wordpress站点的教程

wordpress评论者链接在新窗口中打开的方法

wordpress主题中无法显示浏览量问题的解决方法

更多相关阅读请进入《wordpress》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...