WordPress的have_posts()和the_post()函数
在WordPress的index.php文章循环输出中,通常会有下面一段代码: [pcsh lang=”php” tab_size=”4” message=”” hl_lines=”” provider=”manual”] <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <?php endwhile; ?> <?php endif; ?> [/pcsh] 这里有两个函数,have_posts()和the_post()。 have_posts() 函数:WordPress的have_posts() 默认是一个全局函数。 have_posts函数被调用时实际上是调用全局变量$wp_query->have_posts()成员函数,来简单检查一个全局数组(array)变量$posts的一个循环计数器,以确认是否还有post,如果有返回true(1),如果没有返回false...
WordPress函数:add_action(添加动作)
说明 将函数连接到指定action(动作)。 在Plugin API/Action Reference 上查看动作hook列表。wordpress核心调用do_action() 时触发动作。 用法 [pcsh lang="php" tab_size="4" message="" hl_lines="" provider="manual"] <?php add_action( $tag, $function_to_add, $priority, $accepted_args ); ?> [/pcsh] 参数 $tag (字符串)(必填)$function_to_add 所挂载的动作(action)的名称。(在Plugin API/Action Reference 上查看动作hook列表)。也可以是一个主题或插件文件内部的一个动作,或者特定的标签“all”,这个函数将被所有的钩子(hooks)调用。 默认值:None $function_to_add (回调)(必填)你希望挂载的函数的名称。注:在 PHP“回调”类型文档中...
jQuery 遍历函数
jQuery 遍历函数包括了用于筛选、查找和串联元素的方法。 函数 描述 .add() 将元素添加到匹配元素的集合中。 .andSelf() 把堆栈中之前的元素集添加到当前集合中。 .children() 获得匹配元素集合中每个元素的所有子元素。 .closest() 从元素本身开始,逐级向上级元素匹配,并返回最先匹配的祖先元素。 .contents() 获得匹配元素集合中每个元素的子元素,包括文本和注释节点。 .each() 对 jQuery 对象进行迭代,为每个匹配元素执行函数。 .end() 结束当前链中最近的一次筛选操作,并将匹配元素集合返回到前一次的状态。 .eq() 将匹配元素集合缩减为位于指定索引的新元素。 .filter() 将匹配元素集合缩减为匹配选择器或匹配函数返回值的新元素。 .find() 获得当前匹配元素集合中每个元素的后代,由选择器进行筛选。 .first() 将匹配元素集合缩减为集合中的第一个元素。 .has() 将匹配元素集合缩减为包含特定元素的后代的集合。 .is() 根据选择器检查当前匹...
jQuery 遍历 - prevAll() 方法
prevAll函数的获取顺序: prevAll实际上是从 当前匹配元素 依次向上匹配的 如下实验 [pcsh lang=”php” tab_size=”4” message=”” hl_lines=”” provider=”manual”] <html> <head> <script type="text/javascript" src="/js/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ (function(){ $("#ddd").prevAll("li").each(function(){ alert($(this).text()); }); })(); }); </script> </head> <body> &l...
jQuery - 获得内容和属性
获得内容 - text()、html() 以及 val() 三个简单实用的用于 DOM 操作的 jQuery 方法: text() - 设置或返回所选元素的文本内容 html() - 设置或返回所选元素的内容(包括 HTML 标记) val() - 设置或返回表单字段的值 下面的例子演示如何通过 jQuery text() 和 html() 方法来获得内容: 实例 $("#btn1").click(function(){ alert("Text: " + $("#test").text()); }); $("#btn2").click(function(){ alert("HTML: " + $("#test").html()); }); 获取属性 - attr() jQuery attr() 方法用于获取属性值。 下面的例子演示如何获得链接中 href 属性的值: 实例 $("button").click(function(){ alert($("#w3s").attr("href")); });
jQuery 遍历 - prev() 方法
prev() 获得匹配元素集合中每个元素紧邻的前一个同胞元素,通过选择器进行筛选是可选的。 根据测试,必须是同胞才行,中间不能有任何无关的元素,比如 <body><div class=”selected”><span>Hello</span></div><br><p class=”selected”>Hello Again</p><p>And Again</p> <script>$(“p”).prev(“.selected”).css(“background”, “yellow”);</script> 这段只能搜索到Hello Again,因为前面多了个br,应该不是同胞了 <body><div class=”selected”><span>Hello</span></div>&l...
get_post_meta
示例 <?php $key_1_value = get_post_meta(76, 'key_1', true); ?> 参数 $post_id (整数)(必需)希望从中得到数据的文章的编号。用$post->ID获取文章编号。 默认值:None $key (字符)(必需)字符,字符中含有希望的meta值的名称。 默认值:None $single (布尔值)(可选)如果默认值设为true,函数返回单个字符形式的结果。如果为false或为设置,则函数返回自定义字段的数组。 默认值:false 返回的值 若$single设为false或空,函数返回一个包含指定关键字的所有值的数组 若$single设为true,函数返回指定关键字的第一个值(不是数组) 无论$single值是什么,如果没有指定关键字,函数将返回空的字符。
php include require区别
根据网上其他人的说法,而且没有什么区别 只有发生“错误”时, include只会提示一个警告,然后继续执行 require会抛出一个致命错误,程序停止
wp_verify_nonce
<?php wp_verify_nonce( $nonce, $action ); ?> $nonce(string) (required) Nonce to verify.Default: None$action(string/int) (optional) Action name. Should give the context to what is taking place and be the same when the nonce was created.Default: -1 Return Values (boolean/integer) Boolean false if the nonce is invalid. Otherwise, returns an integer with the value of: 1 – if the nonce has been generated in the past 12 hours or less. 2 – if the nonce was generated between 12 and 24 hours ...
wordpress中有关即时验证的几个_nonce函数
原文地址:http://www.utubon.com/post/877.html 在wordpress中,为了增加系统的验证安全性,内置了一些简单的验证,这些验证可以有效的防治注册、提交等操作,如果开发者在主题开发中,对数据库进行了操作,一定要使用到这些函数,本文就对这几个函数做一个详细的介绍。 一、wp_create_nonce wp_create_nonce的用法很简单,即一般用在链接中 它将有一个参数,这个参数相当于一个唯一标识ID,通过这个ID,你可以再后文的程序中进行检查。它的返回值即nonce,一个随机字符串。 wp_create_nonce(?$action?); 它的使用例如: <?php?$nonce=?wp_create_nonce??('my-nonce');??> <a?href='myplugin.php?_wpnonce=<?php?echo?$nonce??>'>?... <?php$nonce=$_REQUEST[‘_wpnonce’];if?(!?wp_verify_nonce($nonce,...