怎么用WordPress做模板 WordPress网站建站教程

凤凰 2021-1-19 62 1/19

怎么用WordPress做模板 WordPress网站建站教程

下面来教大家做一个简易的wordpress模板(不含style样式的编写),主要是一些相关函数的调用

推荐教程:wordpress教程

1、wordpress模板制作之标题调用

<title><?php bloginfo('name'); ?><?php wp_title(); ?></title>
//格式是:网站名》文章名,比如:卓创威视》无线门铃zc-08
<title><?php the_title(); ?>_<?php bloginfo('name'); ?></title>
//格式是:文章名_网站名,比如:无线门铃zc-08_卓创威视
<a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?></a>
//标题加链接

  第一种<?php wp_title(); ?>默认在标题前加一个》箭头号,可以用在首页调用;而<?php the_title(); ?>纯粹是调用文章标题,可以用在文章和列表页

2、wordpress模板制作之列表调用

<?php if(have_posts()) : ?>
    <?php while(have_posts()) : the_post(); ?>
    //if(have_posts()) – 检查博客是否有日志。while(have_posts()) – 如果有日志,那么当博客有日志的时候,执行下面 the_post() 这个函数。the_post() – 调用具体的日志来显示。
        <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
        //调用标题,带链接
        <?php the_excerpt(); ?>
        //或者用这个调用文章摘要
    <?php endwhile; ?>
        <?php posts_nav_link(); ?>
        //分页导航
<?php else : ?>            
    没有文章   
<?php endif; ?>
//注释:并不是所有的代码都需要两部分用来打开和关闭。有些代码能够自我关闭,这就解释了 have_posts() 和 the_post(); 这两个函数。因为 the_post(); 在 if() 和 while() 的外面,只需要分号去结束或者关闭。

3、wordpress模板制作之文章页调用

<?php if(have_posts()) : ?>
    <?php while(have_posts()) : the_post(); ?>
    //if(have_posts()) – 检查博客是否有日志。while(have_posts()) – 如果有日志,那么当博客有日志的时候,执行下面 the_post() 这个函数。the_post() – 调用具体的日志来显示。
        <h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
        //调用标题,带链接
        <?php the_content(); ?>
        //调用文章全部内容
    <?php endwhile; ?>
        <?php previous_post_link('%link') ?> <?php next_post_link('%link') ?>
        //上一页、下一页导航
<?php else : ?>            
    没有文章
<?php endif; ?>
//注释:并不是所有的代码都需要两部分用来打开和关闭。有些代码能够自我关闭,这就解释了 have_posts() 和 the_post(); 这两个函数。因为 the_post(); 在 if() 和 while() 的外面,只需要分号去结束或者关闭。

以上就是怎么用wordpress做模板的详细内容,更多请关注本站其它相关文章!

- THE END -
Tag:

凤凰

1月19日09:21

最后修改:2021年1月19日
0

非特殊说明,本博所有文章均为博主原创。