记录在开发过程中常用的

引入标签:在一个模板文件里引用另外一个文件

  • get_header()
  • get_footer()
  • get_sidebar()
  • get_template_part()
  • get_search_form()
  • comments_template()      ----引入评论框
<?php
//调用header.php
get_header(); //调用header-one.php
get_header('one'); ?>
<?php
//调用header.php
get_template_part('header'); //调用header-one.php
get_template_part('header','one');
?>
<?php
get_search_form();
//等同
get_search_form(true); //为false时是赋值,需要另外输出
$form=get_search_form(false);
echo $form;
?>

 模版标签

  • bloginfo()
  • wp_title()
  • the_title()
  • the_permalink()
  • the_content()
  • the_excerpt()
  • the_category()
  • the_tags()
  • the_time()
  • comments_popup_link()  ----评论条数
  • edit_post_link()
  • next_post_link()
  • previous_post_link()

bloginfo() 显示博客信息,用法:

<h1><?php bloginfo( 'name' ); ?></h1>
<p><?php bloginfo('description'); ?> </p>

参数:

admin_email          = admin@example.com
atom_url = http://www.example.com/home/feed/atom
charset = UTF-8
comments_atom_url = http://www.example.com/home/comments/feed/atom
comments_rss2_url = http://www.example.com/home/comments/feed
description = Just another WordPress blog
home = http://www.example.com/home (DEPRECATED! use url option instead)
html_type = text/html
language = en-US
name = Testpilot
pingback_url = http://www.example.com/home/wp/xmlrpc.php
rdf_url = http://www.example.com/home/feed/rdf
rss2_url = http://www.example.com/home/feed
rss_url = http://www.example.com/home/feed/rss
siteurl = http://www.example.com/home (DEPRECATED! use url option instead)
stylesheet_directory = http://www.example.com/home/wp/wp-content/themes/largo
stylesheet_url = http://www.example.com/home/wp/wp-content/themes/largo/style.css
template_directory = http://www.example.com/home/wp/wp-content/themes/largo
template_url = http://www.example.com/home/wp/wp-content/themes/largo
text_direction = ltr
url = http://www.example.com/home
version = 3.5
wpurl = http://www.example.com/home/wp

wp_title()

用途:通常用在页面头部的<title>元素中,在不同文件里,返回的值不一样,具体如下:

文章页->文章标题
日期页->日期
分类页->分类标题
作者页->作者名字

用法:

 <?php wp_title( $sep, $display, $seplocation ); ?> 

$sep--分隔符,$display--是否直接显示(不直接显示需要echo才出来),$seplocation--分隔符所在位置

the_title()

 <?php the_title( $before, $after, $echo ); ?>

参数说明:$before 标题前,$after标题后, $echo是否直接输出

用途:需放主循环内,调用发布信息的标题,在不同文件里,返回的值不一样。

<?php if( have_posts() ) : while( have_posts() ) : the_post(); ?>
<!-- 在这里调用数据 -->
<?php the_title();?>
<?php endwhile; ?>
<?php endif; ?>

the_permalink()

用途:调用当前信息的网址,必须在主循环内使用

<?php the_permalink(); ?> 

the_content()

用途:显示内容,

如果文章插入了more标签

<?php the_content( 'Read more ...' ); ?>

有参数的情况下:

the_excerpt()

用途:调用摘要,如果没有填写摘要则截取文章前55个字符

<?php the_excerpt(); ?>

 the_category()

用途:调用当前文章所属分类,必须在主循环内使用

<?php the_category( $separator, $parents, $post_id ); ?> 

参数说明:$separator--分隔符,$parents---父目录控制,$post_id---文章编号

只输出当前文章目录:

 <?php  the_category(); ?> 

去格式化输出当前文章目录:

<?php  the_category('|'); ?> 

子目录和父目录一起调出:

<?php  the_category('|','multiple'); ?> 

the_tags()

用途:调用当前分类所用的标签

<?php the_tags( $before, $sep, $after ); ?> 

参数说明:$before---标签前,$sep--分隔符,$after---标签后

the_time()

用途:调用发表时间,*需放在主循环内

<?php the_time( $d ); ?> 

参数说明:$d---时间显示格式

<?php the_time('Y-m-d h:i'); ?>

输出:2017-01-28 12:09

comments_popup_link()

用途:调用评论条数,并带跳转到该文章的评论框的链接,必须在主循环内使用

<?php comments_popup_link( $zero, $one, $more, $css_class, $none ); ?> 

参数说明:$zero--没评论的时候显示什么,$one---一条评论的时候显示什么,$more---更多评论的时候显示什么,$css_class---链接的css类,$none---文章不允许评论时显示什么

edit_post_link()

用途:有权限编辑文章时显示的编辑链接,必须在主循环内使用

<?php edit_post_link( $link, $before, $after, $id, $class ); ?> 

参数说明:$link---链接文本,$before---链接文本前的文本,$after---链接文本后的文本,$id---文章ID,$class---链接样式

next_post_link(),previous_post_link()

用途:必须在主循环内使用

<?php next_post_link("上一篇: %link") ?>
<?php previous_post_link("下一篇: %link") ?>

更多请参考文档,推荐英文版

wordpress函数参考:
英文官方参考网页:http://codex.wordpress.org/Function_Reference/
中文官方参考网页:http://codex.wordpress.org.cn/%E5%87%BD%E6%95%B0%E5%8F%82%E8%80%83

wordpress模版标签:
英文官方参考网页:http://codex.wordpress.org/Template_Tags/
中文官方参考网页:http://codex.wordpress.org.cn/%E6%A8%A1%E6%9D%BF%E6%A0%87%E7%AD%BE

wordpress引入标签:
英文官方参考网页:http://codex.wordpress.org/Include_Tags
中文官方参考网页:http://codex.wordpress.org.cn/Include_Tags

wordpress条件标签:
英文官方参考网页:http://codex.wordpress.org/Conditional_Tags
中文官方参考网页:http://codex.wordpress.org.cn/%E6%9D%A1%E4%BB%B6%E6%A0%87%E7%AD%BE

WordPress主题开发:数据调用的更多相关文章

  1. 黄聪:《跟黄聪学WordPress主题开发》

    又一个作品完成!<跟黄聪学Wordpress主题开发>,国内最好的Wordpress主题模版开发视频教程!! 目录预览: WordPress官方源文件层式结构讲解 WordPress数据库 ...

  2. wordpress 主题开发

    https://yusi123.com/3205.html https://themeshaper.com/2012/10/22/the-themeshaper-wordpress-theme-tut ...

  3. WordPress 主题开发:从入门到精通(必读)

    本专栏介绍如何开发设计你自己的 WordPress 主题.如果你希望了解更多如何安装和应用主题的内容,请参阅应用主题文档.本文的内容不同于应用主题,因为所讨论的是编写代码去构建你自己的主题的技术内容, ...

  4. WordPress 主题开发 - (三) 开发工具 待翻译

    Before we get started building any WordPress Theme, we’re going to need to get our development tools ...

  5. [转]WordPress主题开发:主题初始化

    本文转自:http://www.cnblogs.com/tinyphp/p/4391182.html 在最简单的情况下,一个WordPress主题由两个文件构成: index.php -------- ...

  6. WordPress主题开发:WP_Query基本用法

    为什么要学WP_Query? wordpress默认会根据网址调用数据,不能满足我们所有建站要求,而WP_Query可以用于查询任何你想要的内容,相当于自定义数据调用. 便于记忆,在讲用法之前我们回顾 ...

  7. WordPress主题开发:主题初始化

    在最简单的情况下,一个WordPress主题由两个文件构成: index.php ------------------主模版 style.css  -------------------主样式表(注意 ...

  8. WordPress 主题开发 - (一) 前言 待翻译

    原文出自: http://themeshaper.com/2012/10/22/the-themeshaper-wordpress-theme-tutorial-2nd-edition/ THE TH ...

  9. WordPress主题开发:制作面包屑导航

    所谓面包屑,就是类似这种:首页 > 公司简介 > 发展历史 展示网站树型结构,并让网站访问者随时知道自己所处的位置,方便返回上几级. 将下面的代码添加到主题的 functions.php ...

  10. WordPress主题开发:style.css主题信息标记

    在最简单的情况下,一个WordPress主题由两个文件构成: index.php ------------------主模版 style.css -------------------主样式表 而且s ...

随机推荐

  1. 【转】手把手教你 Mockito 的使用

    原文链接:https://segmentfault.com/a/1190000006746409 什么是 Mockito Mockito 是一个强大的用于 Java 开发的模拟测试框架, 通过 Moc ...

  2. SpringBoot修改默认端口号,session超时时间

    有时候我们可能需要启动不止一个SpringBoot,而SpringBoot默认的端口号是8080,所以这时候我们就需要修改SpringBoot的默认端口了.修改SpringBoot的默认端口有两种方式 ...

  3. C# 各版本新特性

    C# 2.0 泛型(Generics) 泛型是CLR 2.0中引入的最重要的新特性,使得可以在类.方法中对使用的类型进行参数化. 例如,这里定义了一个泛型类: class MyCollection&l ...

  4. CSS font-family 字体介绍,\5b8b\4f53 表示“宋体”

    font-family采用一种"回退"的形式来保存字体,可以写若干种字体.当第一种字体浏览器不支持的时候,会找第二种字体,一次类推. font-family字体分为两类: 特殊字体 ...

  5. MyISAM引擎和InnoDB引擎的特点

    随着MySQL的不断更新,由于各存储引擎功能特性差异较大,这篇文章主要是介绍如何来选择合适的存储引擎来应对不同的业务场景,朋友们可以根据业务需求,选择合适的存储引擎.^.^ MyISAM 特性 不支持 ...

  6. ***linux下安装xampp,XAMPP目录结构(阿里云安装xampp)

    XAMPP目录结构 重要的文件和目录 文件/目录                              用途 /opt/lampp/bin/ XAMPP 命令库.例如 /opt/lampp/bin ...

  7. 在win7_64bit + ubuntu-12.04-desktop-amd64+VMware-workstation-full-10.0.1-1379776平台上安装ns-allinone-2.35

    step1.  ns-allinone-2.35的下载地址:http://www.isi.edu/nsnam/ns/ns-build.html#allinone step2.  在虚拟机中打开term ...

  8. Codeforces 311B Cats Transport 斜率优化dp

    Cats Transport 出发时间居然能是负的,我服了... 卡了我十几次, 我一直以为斜率优化写搓了. 我们能得出dp方程式 dp[ i ][ j ] = min(dp[ k ][ j - 1 ...

  9. 喊山 BFS

    一个山头呼喊的声音可以被临近的山头同时听到.题目假设每个山头最多有两个能听到它的临近山头.给定任意一个发出原始信号的山头,本题请你找出这个信号最远能传达到的地方. 输入格式: 输入第一行给出3个正整数 ...

  10. 图片视频访问servlet(支持苹果视频断点续传)

    package com.sm.common.servlet; import java.io.File; import java.io.FileInputStream; import java.io.F ...