小码农 – 笔记

小码农小码农

小码农

wordpress,laravel和前端知识学习

$post全局变量详解

文章摘要:

调用方法: <? global $post; var_dump($post); ?> 得到如下数据: object(WP_Post)#3747 (24) { ["ID"]=> int(31) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2016-09-06 11:26:23" ["post_date_gmt"]=> string(19) "2016-09-06 03:26:23" ["post_content"]=> string(909) "<p> 整洁。。。。。。</p>" ["post_title"]=> string(12) "办公环境" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(4) "open" ["ping_status"]=> ......

wordpress首页模版及调用options表数据

文章摘要:

一、主题模板创建 必须文件: style.css index.php 文件内容:style.css /* Theme Name: 主题名称 Theme URI: 主题介绍的网址 Description: 主题简短介绍 Version:1.0.0 版本号 Author: 作者名 Author URI: 作者的网址 Tag: 标签,多个用英文逗号隔开 */ 基础文件: index.php --> 主页模版 style.css --> 主要样式表 header.php footer.php slider.php 404.php archive.php search.php tag.php single.php page.php screenshot.png --> 主题缩略图 二、首页模版 header.php <!doctype html> <html> <head> <meta charset="<? bloginfo('charset');?>"> <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> <meta name="viewport" content="wid......

文章输出函数详解

文章摘要:

1. get_the_category() 获取分类的链接 返回值: cat_ID 类别编号,存储在term_id字段 cat_name 类别名称,存储在name字段 category_nicename 别名,存储在slug字段 category_description 类别描述,存储在description字段 category_parent 父类别编号,没有父类的为0,存储在parent字段 category_count 类别使用的数量,存储在count字段 显示第一个类别的连接: <?php $category = get_the_category(); if($category[0]){ echo '<a href="'.get_category_link($category[0]->term_id ).'">'.$category[0]->cat_name.'</a>'; } ?> 2. 获取文章特色图像 首先,在functions.php中添加代码; add_theme_support('post-thumbnails'); 然后就可以在文章右下角添加特色图像 调用特色图像 利用the_post_thum......

如何循环输出文章列表

文章摘要:

文章是博客主要的组成,因此首先练习如何输出文章。 先判断当前博客是否有文章 have_posts() <? if( have_posts() ){ }else{ ehco '没有文章可以显示'; } ?> 有文章则显示文章 while( have_posts() ){ the_post(); } the_post()函数是获取文章信息,并保存在全局变量 $post 中 <? if( have_posts() ){ while( have_posts() ){ the_post(); } }else{ ehco '没有文章可以显示'; } ?> 显示文章的标题和内容 the_title(); 显示当前文章标题 the_permalink(); 显示当前文章的链接 the_content(); 显示当前文章正文(不是摘要) <? if( have_posts() ){ while( have_posts() ){ the_post(); ?> <h2&......

WordPress主题文件的执行顺序及其层次结构详解

文章摘要:

本文将介绍wordpress主题文件及主题文件执行的顺序和文件的层次结构。就是当你访问一个页面时,我们要看看有哪些模板文件被执行。 通常而言,一个功能完善的主题包含有index.php、page.php、single.php、sidebar.php、style.css、archine.php、、comments.php 和 search.php几个基本文件,WordPress在调用这些文件时会采用优先的原则,即先判断页面的类型,如果有对应的主体文件则调用,否则调用index.php文件,这也验证了前面说的:“一个index.php文件即可成为一个完整的主题”。 如图所示,wordpress在加载主题文件时,会对主题文件进行逐一判断(调用顺序为从上到下): 1. 首页 对于每一个网站,这是第一,也是最重要的一个页面。所以WP提供了极大的范围来让你定制这个页面。让我们看看这个用于显示首页的文件的层次。 front-page.php home.ph......