<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>wordpress函数 &#8211; 九创科技</title>
	<atom:link href="https://www.3code.cn/tag/wordpress%e5%87%bd%e6%95%b0/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.3code.cn</link>
	<description>Wordpress外贸企业主题, Wp企业主题, wordpress企业主题, wordpress主题定制, WORDPRESS外贸网站建设SEO</description>
	<lastBuildDate>Tue, 30 Oct 2012 06:14:10 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>wordpress常用函数集分类说明</title>
		<link>https://www.3code.cn/wordpress-functions-2/</link>
		
		<dc:creator><![CDATA[寒林]]></dc:creator>
		<pubDate>Tue, 30 Oct 2012 06:08:23 +0000</pubDate>
				<category><![CDATA[WORDPRESS教程]]></category>
		<category><![CDATA[wordpress函数]]></category>
		<guid isPermaLink="false">https://www.3code.cn/?p=3075</guid>

					<description><![CDATA[WordPress模板基本文件 style.css 样式表文件 index.php 主页文件 sin<a class="moretag" href="https://www.3code.cn/wordpress-functions-2/"> 阅读更多&#8230;</a>]]></description>
										<content:encoded><![CDATA[<p><strong>WordPress模板基本文件</strong></p>
<p>style.css 样式表文件<br />
index.php 主页文件<br />
single.php 日志单页文件<br />
page.php 页面文件<br />
archvie.php 分类和日期存档页文件<br />
searchform.php 搜索表单文件<br />
search.php 搜索页面文件<br />
comments.php 留言区域文件(包括留言列表和留言框)<br />
404.php 404错误页面<br />
header.php 网页头部文件<br />
sidebar.php 网页侧边栏文件<br />
footer.php 网页底部文件</p>
<p><strong>WordPress Header头部 PHP代码 (注: 也就是位于&lt;head&gt;和&lt;/head&gt;之间的PHP代码)</strong></p>
<p>&lt;?php bloginfo(’name’); ?&gt; 网站标题<br />
&lt;?php wp_title(); ?&gt; 日志或页面标题<br />
&lt;?php bloginfo(’stylesheet_url’); ?&gt; WordPress主题样式表文件style.css的相对地址<br />
&lt;?php bloginfo(’pingback_url’); ?&gt; WordPress博客的Pingback地址<br />
&lt;?php bloginfo(’template_url’); ?&gt; WordPress主题文件的相对地址<br />
&lt;?php bloginfo(’version’); ?&gt; 博客的WordPress版本<br />
&lt;?php bloginfo(’atom_url’); ?&gt; WordPress博客的Atom地址<br />
&lt;?php bloginfo(’rss2_url’); ?&gt; WordPress博客的RSS2地址<br />
&lt;?php bloginfo(’url’); ?&gt; WordPress博客的绝对地址<br />
&lt;?php bloginfo(’name’); ?&gt; WordPress博客的名称<br />
&lt;?php bloginfo(’html_type’); ?&gt; 网站的HTML版本<br />
&lt;?php bloginfo(’charset’); ?&gt; 网站的字符编码格式</p>
<p><strong>WordPress 主体模板 PHP代码</strong></p>
<p>&lt;?php the_content(); ?&gt; 日志内容<br />
&lt;?php if(have_posts()) : ?&gt; 确认是否有日志<br />
&lt;?php while(have_posts()) : the_post(); ?&gt; 如果有，则显示全部日志<br />
&lt;?php endwhile; ?&gt; 结束PHP函数”while”<br />
&lt;?php endif; ?&gt; 结束PHP函数”if”<br />
&lt;?php get_header(); ?&gt; header.php文件的内容<br />
&lt;?php get_sidebar(); ?&gt; sidebar.php文件的内容<br />
&lt;?php get_footer(); ?&gt; footer.php文件的内容<br />
&lt;?php the_time(’m-d-y’) ?&gt; 显示格式为”02-19-08″的日期<br />
&lt;?php comments_popup_link(); ?&gt; 显示一篇日志的留言链接<br />
&lt;?php the_title(); ?&gt; 显示一篇日志或页面的标题<br />
&lt;?php the_permalink() ?&gt; 显示一篇日志或页面的永久链接/URL地址<br />
&lt;?php the_category(’, ‘) ?&gt; 显示一篇日志或页面的所属分类<br />
&lt;?php the_author(); ?&gt; 显示一篇日志或页面的作者<br />
&lt;?php the_ID(); ?&gt; 显示一篇日志或页面的ID<br />
&lt;?php edit_post_link(); ?&gt; 显示一篇日志或页面的编辑链接<br />
&lt;?php get_links_list(); ?&gt; 显示Blogroll中的链接<br />
&lt;?php comments_template(); ?&gt; comments.php文件的内容<br />
&lt;?php wp_list_pages(); ?&gt; 显示一份博客的页面列表<br />
&lt;?php wp_list_cats(); ?&gt; 显示一份博客的分类列表<br />
&lt;?php next_post_link(’ %link ‘) ?&gt; 下一篇日志的URL地址<br />
&lt;?php previous_post_link(’%link’) ?&gt; 上一篇日志的URL地址<br />
&lt;?php get_calendar(); ?&gt; 调用日历<br />
&lt;?php wp_get_archives() ?&gt; 显示一份博客的日期存档列表<br />
&lt;?php posts_nav_link(); ?&gt; 显示较新日志链接(上一页)和较旧日志链接（下一页）<br />
&lt;?php bloginfo(’description’); ?&gt; 显示博客的描述信息</p>
<p><strong>其它的一些WordPress模板代码</strong></p>
<p>/%postname%/ 显示博客的自定义永久链接<br />
&lt;?php the_search_query(); ?&gt; 搜索表单的值<br />
&lt;?php _e(’Message’); ?&gt; 打印输出信息<br />
&lt;?php wp_register(); ?&gt; 显示注册链接<br />
&lt;?php wp_loginout(); ?&gt; 显示登入/登出链接<br />
&lt;!–next page–&gt; 在日志或页面中插入分页<br />
&lt;!–more–&gt; 截断日志<br />
&lt;?php wp_meta(); ?&gt; 显示管理员的相关控制信息<br />
&lt;?php timer_stop(1); ?&gt; 显示载入页面的时间<br />
&lt;?php echo get_num_queries(); ?&gt; 显示载入页面查询</p>
<p>&nbsp;</p>
<p><strong>1. wordpress调用最新文章</strong></p>
<p>WordPress最新文章的调用可以使用一行很简单的模板标签wp_get_archvies来实现. 代码如下：</p>
<p>&lt;?php get_archives(‘postbypost’, 10); ?&gt; (显示10篇最新更新文章)</p>
<p>或者</p>
<p>&lt;?php wp_get_archives(‘type=postbypost&amp;limit=20&amp;format=custom’); ?&gt;</p>
<p>后面这个代码显示你博客中最新的20篇文章，其中format=custom这里主要用来自定义这份文章列表的显示样式。具体的参数和使用方法你可 以参考官方的使用说明- wp_get_archvies。(fromat=custom也可以不要，默认以UL列表显示文章标题。)</p>
<p>补充: 通过WP的query_posts()函数也能调用最新文章列表， 虽然代码会比较多一点，但可以更好的控制Loop的显示，比如你可以设置是否显示摘要。具体的使用方法也可以查看官方的说明。</p>
<p><strong>2. wordpress调用随机文章</strong></p>
<p>&lt;?php<br />
$rand_posts = get_posts(‘numberposts=10&amp;orderby=rand’);<br />
foreach( $rand_posts as $post ) :<br />
?&gt;<br />
&lt;!–下面是你想自定义的Loop–&gt;<br />
&lt;li&gt;&lt;a href=”&lt;?php the_permalink(); ?&gt;”&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt;<br />
&lt;?php endforeach; ?&gt;</p>
<p><strong>3. wordpress调用最新留言</strong></p>
<p>下面是我之前在一个WordPress主题中代到的最新留言代码，具体也记不得是哪个主题了。该代码直接调用数据库显示一份最新留言。其中 LIMIT 10限制留言显示数量。绿色部份则是每条留言的输出样式。</p>
<p>&lt;?php<br />
global $wpdb;<br />
$sql = “SELECT DISTINCT ID, post_title, post_password, comment_ID,<br />
comment_post_ID, comment_author, comment_date_gmt, comment_approved,<br />
comment_type,comment_author_url,<br />
SUBSTRING(comment_content,1,30) AS com_excerpt<br />
FROM $wpdb-&gt;comments<br />
LEFT OUTER JOIN $wpdb-&gt;posts ON ($wpdb-&gt;comments.comment_post_ID =<br />
$wpdb-&gt;posts.ID)<br />
WHERE comment_approved = ’1′ AND comment_type = ” AND<br />
post_password = ”<br />
ORDER BY comment_date_gmt DESC<br />
LIMIT 10″;<br />
$comments = $wpdb-&gt;get_results($sql);<br />
$output = $pre_HTML;   foreach ($comments as $comment) {<br />
$output .= “n&lt;li&gt;”.strip_tags($comment-&gt;comment_author)<br />
.”:” . ” &lt;a href=”&#8221; . get_permalink($comment-&gt;ID) .<br />
“#comment-” . $comment-&gt;comment_ID . “” title=”on ” .<br />
$comment-&gt;post_title . “”&gt;” . strip_tags($comment-&gt;com_excerpt)<br />
.”&lt;/a&gt;&lt;/li&gt;”;<br />
}   $output .= $post_HTML;<br />
echo $output;?&gt;</p>
<p><strong>4.wordpress调用相关文章</strong></p>
<p>在文章页显示相关文章</p>
<p>&lt;?php</p>
<p>$tags = wp_get_post_tags($post-&gt;ID);</p>
<p>if ($tags) {</p>
<p>$first_tag = $tags[0]-&gt;term_id;</p>
<p>$args=array(</p>
<p>‘tag__in’ =&gt; array($first_tag),</p>
<p>‘post__not_in’ =&gt; array($post-&gt;ID),</p>
<p>‘showposts’=&gt;10,</p>
<p>‘caller_get_posts’=&gt;1</p>
<p>);</p>
<p>$my_query = new WP_Query($args);</p>
<p>if( $my_query-&gt;have_posts() ) {</p>
<p>while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); ?&gt;</p>
<p>&lt;li&gt;&lt;a href=”&lt;?php the_permalink() ?&gt;” rel=”bookmark” title=”&lt;?php the_title_attribute(); ?&gt;”&gt;&lt;?php the_title();?&gt; &lt;?php comments_number(‘ ‘,’(1)’,'(%)’); ?&gt;&lt;/a&gt;&lt;/li&gt;</p>
<p>&lt;?php</p>
<p>endwhile;</p>
<p>}</p>
<p>}</p>
<p>wp_reset_query();</p>
<p>?&gt;</p>
<p><strong>5.wordpress调用指定分类的文章</strong></p>
<p>&lt;?php $posts = get_posts( “category=4&amp;numberposts=10″ ); ?&gt;<br />
&lt;?php if( $posts ) : ?&gt;<br />
&lt;ul&gt;&lt;?php foreach( $posts as $post ) : setup_postdata( $post ); ?&gt;<br />
&lt;li&gt;<br />
&lt;a href=”&lt;?php the_permalink() ?&gt;” rel=”bookmark” title=”&lt;?php the_title(); ?&gt;”&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;<br />
&lt;/li&gt;<br />
&lt;?php endforeach; ?&gt;<br />
&lt;/ul&gt;<br />
&lt;?php endif; ?&gt;</p>
<p>&nbsp;</p>
<p><strong>6.wordpress去评论者链接的评论输出</strong></p>
<p>&lt;?php</p>
<p>global $wpdb;</p>
<p>$sql = “SELECT DISTINCT ID, post_title, post_password, comment_ID,</p>
<p>comment_post_ID, comment_author, comment_date_gmt, comment_approved,</p>
<p>comment_type,comment_author_url,</p>
<p>SUBSTRING(comment_content,1,14) AS com_excerpt</p>
<p>FROM $wpdb-&gt;comments</p>
<p>LEFT OUTER JOIN $wpdb-&gt;posts ON ($wpdb-&gt;comments.comment_post_ID =</p>
<p>$wpdb-&gt;posts.ID)</p>
<p>WHERE comment_approved = ’1′ AND comment_type = ” AND</p>
<p>post_password = ”</p>
<p>ORDER BY comment_date_gmt DESC</p>
<p>LIMIT 10″;</p>
<p>$comments = $wpdb-&gt;get_results($sql);</p>
<p>$output = $pre_HTML;</p>
<p>foreach ($comments as $comment) {</p>
<p>$output .= “\n&lt;li&gt;”.strip_tags($comment-&gt;comment_author)</p>
<p>.”:” . ” &lt;a href=\”&#8221; . get_permalink($comment-&gt;ID) .</p>
<p>“#comment-” . $comment-&gt;comment_ID . “\” title=\”on ” .</p>
<p>$comment-&gt;post_title . “\”&gt;” . strip_tags($comment-&gt;com_excerpt)</p>
<p>.”&lt;/a&gt;&lt;/li&gt;”;</p>
<p>}</p>
<p>$output .= $post_HTML;</p>
<p>echo $output;?&gt;</p>
<p><strong>7.wordpress调用含gravatar头像的评论输出</strong></p>
<p>&lt;?php</p>
<p>global $wpdb;</p>
<p>$sql = “SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved,comment_author_email, comment_type,comment_author_url, SUBSTRING(comment_content,1,10) AS com_excerpt FROM $wpdb-&gt;comments LEFT OUTER JOIN $wpdb-&gt;posts ON ($wpdb-&gt;comments.comment_post_ID = $wpdb-&gt;posts.ID) WHERE comment_approved = ’1′ AND comment_type = ” AND comment_author != ‘郑 永’ AND post_password = ” ORDER BY comment_date_gmt DESC LIMIT 10″;</p>
<p>$comments = $wpdb-&gt;get_results($sql);</p>
<p>$output = $pre_HTML;</p>
<p>foreach ($comments as $comment) {</p>
<p>$output .= “\n&lt;li&gt;”.get_avatar(get_comment_author_email(‘comment_author_email’), 18). ” &lt;a href=\”&#8221; . get_permalink($comment-&gt;ID) . “#comment-” . $comment-&gt;comment_ID . “\” title=\”&#8221; . $comment-&gt;post_title . ” 上的评论\”&gt;”. strip_tags($comment-&gt;comment_author) .”： “. strip_tags($comment-&gt;com_excerpt) .”&lt;/a&gt;&lt;/li&gt;”;</p>
<p>}</p>
<p>$output .= $post_HTML;</p>
<p>$output = convert_smilies($output);</p>
<p>echo $output;</p>
<p>?&gt;</p>
<p>上面代码把comment_author的值改成你的ID，18是头像大小，10是评论数量。</p>
<p><strong>8.wordpress调用网站统计大全</strong></p>
<p>1、日志总数：</p>
<p>&lt;?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts-&gt;publish;?&gt;</p>
<p>2、草稿数目：</p>
<p>&lt;?php $count_posts = wp_count_posts(); echo $draft_posts = $count_posts-&gt;draft; ?&gt;</p>
<p>3、评论总数：</p>
<p>&lt;?php echo $wpdb-&gt;get_var(“SELECT COUNT(*) FROM $wpdb-&gt;comments”);?&gt;</p>
<p>4、成立时间：</p>
<p>&lt;?php echo floor((time()-strtotime(“2008-8-18″))/86400); ?&gt;</p>
<p>5、标签总数：</p>
<p>&lt;?php echo $count_tags = wp_count_terms(‘post_tag’); ?&gt;</p>
<p>6、页面总数：</p>
<p>&lt;?php $count_pages = wp_count_posts(‘page’); echo $page_posts = $count_pages-&gt;publish; ?&gt;</p>
<p>7、分类总数：</p>
<p>&lt;?php echo $count_categories = wp_count_terms(‘category’); ?&gt;</p>
<p>8、链接总数：</p>
<p>&lt;?php $link = $wpdb-&gt;get_var(“SELECT COUNT(*) FROM $wpdb-&gt;links WHERE link_visible = ‘Y’”); echo $link; ?&gt;</p>
<p>9、用户总数：</p>
<p>&lt;?php $users = $wpdb-&gt;get_var(“SELECT COUNT(ID) FROM $wpdb-&gt;users”); echo $users; ?&gt;</p>
<p>10、最后更新：</p>
<p>&lt;?php $last = $wpdb-&gt;get_results(“SELECT MAX(post_modified) AS MAX_m FROM $wpdb-&gt;posts WHERE (post_type = ‘post’ OR post_type = ‘page’) AND (post_status = ‘publish’ OR post_status = ‘private’)”);$last = date(‘Y-n-j’, strtotime($last[0]-&gt;MAX_m));echo $last; ?&gt;</p>
<p>&nbsp;</p>
<p><strong>9.wordpress判断语句</strong></p>
<p>is_single()</p>
<p>判断是否是具体文章的页面</p>
<p>is_single(’2′)</p>
<p>判断是否是具体文章（id=2）的页面</p>
<p>is_single(’Beef Stew’)</p>
<p>判断是否是具体文章（标题判断）的页面</p>
<p>is_single(’beef-stew’)</p>
<p>判断是否是具体文章（slug判断）的页面</p>
<p>comments_open()</p>
<p>是否留言开启</p>
<p>pings_open()</p>
<p>是否开启ping</p>
<p>is_page()</p>
<p>是否是页面</p>
<p>is_page(’42′)</p>
<p>id判断，即是否是id为42的页面</p>
<p>is_page(’About Me’)</p>
<p>判断标题</p>
<p>is_page(’about-me’)</p>
<p>slug判断</p>
<p>is_category()</p>
<p>是否是分类</p>
<p>is_category(’6′)</p>
<p>id判断，即是否是id为6的分类</p>
<p>is_category(’Cheeses’)</p>
<p>分类title判断</p>
<p>is_category(’cheeses’)</p>
<p>分类 slug判断</p>
<p>in_category(’5′)</p>
<p>判断当前的文章是否属于分类5</p>
<p>is_author()</p>
<p>将所有的作者的页面显示出来</p>
<p>is_author(’1337′)</p>
<p>显示author number为1337的页面</p>
<p>is_author(’Elite Hacker’)</p>
<p>通过昵称来显示当前作者的页面</p>
<p>is_author(’elite-hacker’)</p>
<p>下面是通过不同的判断实现以年、月、日、时间等方式来显示归档</p>
<p>is_date()</p>
<p>is_year()</p>
<p>is_month()</p>
<p>is_day()</p>
<p>is_time()</p>
<p>判断当前是否是归档页面</p>
<p>is_archive()</p>
<p>判断是否是搜索</p>
<p>is_search()</p>
<p>判断页面是否404</p>
<p>is_404()</p>
<p>判断是否翻页，比如你当前的blog是http://domain.com 显示http://domain.com?paged=2的时候，这个判断将返 回真，通过这个函数可以配合is_home来控制某些只能在首页显示的界面，</p>
<p>例如：</p>
<p>&lt;?php if(is_single()):?&gt;</p>
<p>//这里写你想显示的内容，包括函数</p>
<p>&lt;?php endif;?&gt;</p>
<p>或者：</p>
<p>&lt;?php if(is_home() &amp;&amp; !is_paged() ):?&gt;</p>
<p>//这里写你想显示的内容，包括函数</p>
<p>&lt;?php endif;?&gt;</p>
<p><strong>10.wordpress 非插件调用评论表情</strong></p>
<p>&lt;!–smilies–&gt;<br />
&lt;?php</p>
<p>function wp_smilies() {</p>
<p>global $wpsmiliestrans;</p>
<p>if ( !get_option(‘use_smilies’) or (empty($wpsmiliestrans))) return;</p>
<p>$smilies = array_unique($wpsmiliestrans);</p>
<p>$link=”;</p>
<p>foreach ($smilies as $key =&gt; $smile) {</p>
<p>$file = get_bloginfo(‘wpurl’).’/wp-includes/images/smilies/’.$smile;</p>
<p>$value = ” “.$key.” “;</p>
<p>$img = “&lt;img src=\”{$file}\” alt=\”{$smile}\” /&gt;”;</p>
<p>$imglink = htmlspecialchars($img);</p>
<p>$link .= “&lt;a href=\”#commentform\” title=\”{$smile}\” onclick=\”document.getElementById(‘comment’).value += ‘{$value}’\”&gt;{$img}&lt;/a&gt; ”;</p>
<p>}</p>
<p>echo ‘&lt;div&gt;’.$link.’&lt;/div&gt;’;</p>
<p>}</p>
<p>?&gt;</p>
<p>&lt;?php wp_smilies();?&gt;</p>
<p>&lt;!–smilies—&gt;</p>
<p>将以上代码复制到 comments.php 中合适的位置。</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>为 WordPress分类 添加图标</title>
		<link>https://www.3code.cn/%e4%b8%ba-wordpress%e5%88%86%e7%b1%bb-%e6%b7%bb%e5%8a%a0%e5%9b%be%e6%a0%87/</link>
		
		<dc:creator><![CDATA[寒林]]></dc:creator>
		<pubDate>Sat, 10 Sep 2011 05:57:24 +0000</pubDate>
				<category><![CDATA[WORDPRESS教程]]></category>
		<category><![CDATA[wordpress函数]]></category>
		<category><![CDATA[wordpress教程]]></category>
		<guid isPermaLink="false">https://www.3code.cn/?p=2813</guid>

					<description><![CDATA[实现此功能的核心问题是，在主循环中能根据分类自动调用不同图标。而利用 get_the_category() 函数获取分类名称的代码为：]]></description>
										<content:encoded><![CDATA[<p>WordPress 默认没有添加分类图标的选项。通过 get_the_category() 函数，可以实现类似芒果首页的分类图标效果。</p>
<p>实现此功能的核心问题是，在主循环中能根据分类自动调用不同图标。而利用 get_the_category() 函数获取分类名称的代码为：</p>
<p>&lt;?php foreach((get_the_category()) as $cat){echo $cat-&gt;category_nicename;}?&gt;</p>
<p>这样就得到了因分类而异的代码。基于此，只需在模板中嵌入图标调用路径即可：</p>
<p>&lt;img src=&#8221;&lt;?php bloginfo(&#8216;template_url&#8217;);?&gt;/image/icon_&lt;?php foreach((get_the_category()) as $cat){echo $cat-&gt;category_nicename;}?&gt;.gif&#8221; /&gt;</p>
<p>当然，需要为每个分类定制不同图标，并存为 “icon_分类名称.gif” 的形式至指定目录。</p>
<p>为分类图标加上链接和描述文字后，完整代码如下：</p>
<p>&lt;a href=&#8221;&lt;?php bloginfo(&#8216;url&#8217;); ?&gt;/category/&lt;?php foreach((get_the_category()) as $cat){echo $cat-&gt;category_nicename;}?&gt;&#8221; title=&#8221;&lt;?php foreach((get_the_category()) as $cat){echo $cat-&gt;cat_name;}?&gt;&#8221;&gt;<br />
&lt;img src=&#8221;&lt;?php bloginfo(&#8216;template_url&#8217;);?&gt;/image/icon_&lt;?php foreach((get_the_category()) as $cat){echo $cat-&gt;category_nicename;}?&gt;.gif&#8221; /&gt;<br />
&lt;/a&gt;</p>
<p>如果嫌修改代码过于麻烦，也可以使用 Category Icons 插件，该插件可以为分类指定不同图标，提供了详细的后台设置面板，操作更为简便，容易上手。</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>wordpress函数-get_pages()</title>
		<link>https://www.3code.cn/wordpress%e5%87%bd%e6%95%b0-get_pages/</link>
		
		<dc:creator><![CDATA[寒林]]></dc:creator>
		<pubDate>Mon, 08 Aug 2011 02:18:24 +0000</pubDate>
				<category><![CDATA[WORDPRESS教程]]></category>
		<category><![CDATA[wordpress函数]]></category>
		<guid isPermaLink="false">https://www.3code.cn/?p=2781</guid>

					<description><![CDATA[get_pages( )函数用于获取博客中已定义页面的列表。下面是它的典型用法。]]></description>
										<content:encoded><![CDATA[<p><strong>常用函数-get_pages()</strong><br />
<strong>说明</strong><br />
get_pages( )函数用于获取博客中已定义页面的列表。下面是它的典型用法。</p>
<p><strong>用法</strong><br />
&lt;?php get_pages(&#8216;arguments&#8217;); ?&gt;</p>
<p><strong>示例</strong><br />
<span style="text-decoration: underline;">在下拉列表中显示页面</span></p>
<p>这是一个包括所有页面的下拉列表的实例。请注意如何在传递页面编号后，通过调用get_page_link函数来获取页面链接。</p>
<p>&lt;select name=\&#8221;page-dropdown\&#8221;<br />
onchange=&#8217;document.location.href=this.options[this.selectedIndex].value;&#8217;&gt;<br />
&lt;option value=\&#8221;\&#8221;&gt;<br />
&lt;?php echo attribute_escape(__(&#8216;Select page&#8217;)); ?&gt;&lt;/option&gt;<br />
&lt;?php<br />
$pages = get_pages();<br />
foreach ($pages as $pagg) {<br />
$option = &#8216;&lt;option value=\&#8221;&#8216;.get_page_link($pagg-&gt;ID).&#8217;\&#8221;&gt;&#8217;;<br />
$option .= $pagg-&gt;post_title;<br />
$option .= &#8216;&lt;/option&gt;&#8217;;<br />
echo $option;<br />
}<br />
?&gt;<br />
&lt;/select&gt;<br />
以文章形式显示目前页面的子页面</p>
<p>&lt;?php<br />
$pages = get_pages(&#8216;child_of=&#8217;.$post-&gt;ID.&#8217;&amp;sort_column=post_date&amp;sort_order=desc&#8217;);<br />
$count = 0;<br />
foreach($pages as $page)<br />
{<br />
$content = $page-&gt;post_content;<br />
if(!$content)<br />
continue;<br />
if($count &gt;= 2)<br />
break;<br />
$count++;<br />
$content = apply_filters(&#8216;the_content&#8217;, $content);<br />
?&gt;<br />
&lt;h2&gt;&lt;a href=\&#8221;&lt;?php echo get_page_link($page-&gt;ID) ?&gt;\&#8221;&gt;&lt;?php echo $page-&gt;post_title ?&gt;&lt;/a&gt;&lt;/h2&gt;<br />
&lt;div class=\&#8221;entry\&#8221;&gt;&lt;?php echo $content ?&gt;&lt;/div&gt;<br />
&lt;?php<br />
}<br />
?&gt;<br />
<strong>参数</strong><br />
sort_column (字符)</p>
<p>按不同方式对页面列表进行排序。默认设置成按页面标题的字母顺序排序。</p>
<p>&#8216;post_title&#8217; —— 按页面标题的字母顺序排序——默认<br />
&#8216;menu_order&#8217; —— 按页面顺序（Page Order）进行排序。注意页面顺序和页面编号的区别。页面编号是由WordPress为每篇文章或页面设定的独有的数字，而页面顺序则由用户在管理栏的Write&gt;Pages中设置。<br />
&#8216;post_date&#8217; —— 按页面创建日期排序。<br />
&#8216;post_modified&#8217; —— 按最后修改时间进行排序。<br />
&#8216;ID&#8217; —— 按页面序列编号排序。<br />
&#8216;post_author&#8217; —— 按页面创建者的序列编号排序。<br />
&#8216;post_name&#8217; —— 按页面缩略名的字母顺序排序。</p>
<p>注意：sort_column参数可按WordPress数据库 wp_post table中任意字段的描述符来对页面列表进行排序。下面给出一些实用示例。</p>
<p>sort_order (字符)</p>
<p>更改页面列表的排列顺序（升序或降序）。默认为升序。可能的值为：</p>
<p>&#8216;asc&#8217; ——按从低到高顺序排列（默认）<br />
&#8216;desc&#8217; —— 按从高到低顺序排列</p>
<p>exclude (字符)</p>
<p>定义一列页面编号并用逗号隔开，将其从已有列表中删除（例如：&#8217;exclude=3，7，1&#8217;）。无默认值。</p>
<p>include (字符)</p>
<p>仅包含get_pages生成的特定页面列表。include参数与exclude同样用逗号将页面编号隔开。无默认值。</p>
<p>child_of (整数)</p>
<p>仅显示单个页面的子页面；值为默认编号。默认值为0（显示所有页面）。注意child_of参数不仅获取直系子页面，也会从已知编号中获取“孙页面”。</p>
<p>0 ——默认，不限制子页面</p>
<p>parent (整数)</p>
<p>显示以该整数为父级的页面。默认值为-1（显示所有页面）。注意这可限制child_of参数的“深度”，因此只能检索到下一级页面。</p>
<p>-1 ——默认，不限制父页面</p>
<p>exclude_tree (整数)</p>
<p>与&#8217;child_of&#8217;相反，&#8217;exclude_tree&#8217;从结果中移除已知编号的所有子页面。也可用于隐藏已知页面的所有子页面。该参数还可联合&#8217;child_of&#8217; 的值以隐藏孙页面。在2.7版本中该参数可用。</p>
<p>hierarchical</p>
<p>（布尔型）在上级页面列表下以缩进方式显示下级页面。默认值为true（在父级列表项下显示其子页面）。可能的值有：</p>
<p>1（true）——默认<br />
0（false）</p>
<p>meta_key</p>
<p>（字符）仅包含含有该自定义字段关键字的页面（与meta_value字段联合使用）。</p>
<p>meta_value</p>
<p>（字符）仅包含含有该自定义字段值的页面（与meta_key字段联合使用）。</p>
<p>authors(字符)</p>
<p>仅包含给定作者所写的文章。<br />
返回值</p>
<p>返回一个数组，数组中包含所有与请求匹配的页面。</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>无插件调用WordPress随机文章、最新文章、最热文章</title>
		<link>https://www.3code.cn/%e6%97%a0%e6%8f%92%e4%bb%b6%e8%b0%83%e7%94%a8wordpress%e9%9a%8f%e6%9c%ba%e6%96%87%e7%ab%a0%e3%80%81%e6%9c%80%e6%96%b0%e6%96%87%e7%ab%a0%e3%80%81%e6%9c%80%e7%83%ad%e6%96%87%e7%ab%a0/</link>
		
		<dc:creator><![CDATA[寒林]]></dc:creator>
		<pubDate>Mon, 25 Jul 2011 09:27:12 +0000</pubDate>
				<category><![CDATA[WORDPRESS教程]]></category>
		<category><![CDATA[wordpress函数]]></category>
		<category><![CDATA[wordpress教程]]></category>
		<guid isPermaLink="false">https://www.3code.cn/?p=2758</guid>

					<description><![CDATA[不用插件调用WordPress随机文章、最新文章、和30天内最热文章。今天介绍的是不用插件调用WordPress随机文章、最新文章和30天内最热的文章。随机文章对于SEO而言是非常有用的，就算你的网站长时间不更新，快照也会经常更新不会停歇。所以说调用随机文章是非常有必要的，一般调用在边栏比较好。具体方法如下:]]></description>
										<content:encoded><![CDATA[<p>不用插件调用WordPress随机文章、最新文章、和30天内最热文章。</p>
<p>今天介绍的是不用插件调用WordPress随机文章、最新文章和30天内最热的文章。</p>
<p>随机文章对于SEO而言是非常有用的，就算你的网站长时间不更新，快照也会经常更新不会停歇。所以说调用随机文章是非常有必要的，一般调用在边栏比较好。具体方法如下:</p>
<p><strong>不用插件调用WordPress随机文章</strong></p>
<p><em>&lt;ul&gt;&lt;li&gt;&lt;h3&gt;&lt;?php _e(&#8216;随机推荐&#8217;); ?&gt;&lt;/h3&gt;&lt;ul&gt;&lt;?php $rand_posts = get_posts(&#8216;numberposts=6&amp;orderby=rand&#8217;);  foreach( $rand_posts as $post ) : ?&gt;&lt;li&gt;&lt;a href=&#8221;&lt;?php the_permalink(); ?&gt;&#8221; title=&#8221;&lt;?php the_title(); ?&gt;&#8221;&gt;&lt;?php echo mb_strimwidth(get_the_title(), 0, 42, &#8216;&#8230;&#8217;); ?&gt;&lt;/a&gt;&lt;/li&gt;&lt;?php endforeach; ?&gt;&lt;/ul&gt;&lt;/ul&gt;</em></p>
<p><strong>不用插件调用WordPress最新文章</strong></p>
<p>&lt;ul&gt;&lt;li&gt;&lt;h3&gt;&lt;?php _e(&#8216;最新文章&#8217;); ?&gt;&lt;/h3&gt;&lt;?php query_posts(&#8220;showposts=6&amp;caller_get_posts=1&amp;orderby=date&amp;order=DESC&#8221;); ?&gt;&lt;ul&gt;&lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;&lt;li&gt;&lt;a href=&#8221;&lt;?php the_permalink() ?&gt;&#8221; title=&#8221;&lt;?php the_title() ?&gt;&#8221;&gt;&lt;?php echo mb_strimwidth(get_the_title(), 0, 42, &#8216;&#8230;&#8217;); ?&gt;&lt;/a&gt;&lt;/li&gt;&lt;?php endwhile; endif; ?&gt;&lt;/ul&gt;&lt;/li&gt;</p>
<p><strong>不用插件调用WordPress30内最热文章</strong></p>
<p><em>&lt;li&gt;&lt;h3&gt;&lt;?php _e(&#8216;最热文章&#8217;); ?&gt;&lt;/h3&gt;&lt;?php  function filter_where($where = &#8221;) { //posts in the last 30 days $where .= &#8221; AND post_date &gt; &#8216;&#8221; . date(&#8216;Y-m-d&#8217;, strtotime(&#8216;-30 days&#8217;)) . &#8220;&#8216;&#8221;; return $where;  } add_filter(&#8216;posts_where&#8217;, &#8216;filter_where&#8217;); query_posts(&#8220;showposts=8&amp;v_sortby=views&amp;caller_get_posts=1&amp;orderby=date&amp;order=desc&#8221;) ?&gt;&lt;ul&gt;&lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;&lt;li&gt;&lt;a href=&#8221;&lt;?php the_permalink() ?&gt;&#8221; title=&#8221;&lt;?php the_title() ?&gt;&#8221;&gt;&lt;?php echo mb_strimwidth(get_the_title(), 0, 42, &#8216;&#8230;&#8217;); ?&gt; &lt;/a&gt;&lt;/li&gt;&lt;?php endwhile; endif; ?&gt;&lt;?php wp_reset_query(); ?&gt;&lt;/ul&gt;&lt;/li&gt;</em></p>
<p><em>其中&lt;?php echo mb_strimwidth(get_the_title(), 0, 42, &#8216;&#8230;&#8217;); ?&gt; 使用的是 控制</em></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>wordpress判断用户是否登录</title>
		<link>https://www.3code.cn/wordpress%e5%88%a4%e6%96%ad%e7%94%a8%e6%88%b7%e6%98%af%e5%90%a6%e7%99%bb%e5%bd%95/</link>
		
		<dc:creator><![CDATA[寒林]]></dc:creator>
		<pubDate>Mon, 06 Jun 2011 14:05:58 +0000</pubDate>
				<category><![CDATA[WORDPRESS教程]]></category>
		<category><![CDATA[WORDPRESS主题技术]]></category>
		<category><![CDATA[wordpress函数]]></category>
		<category><![CDATA[wordpress教程]]></category>
		<guid isPermaLink="false">https://www.3code.cn/?p=2709</guid>

					<description><![CDATA[根据当前访问者是否登录返回布尔值true或false。]]></description>
										<content:encoded><![CDATA[<p>is_user_logged_in()</p>
<p><strong>说明 </strong><br />
根据当前访问者是否登录返回布尔值true或false。</p>
<p><strong>参数 </strong><br />
该函数不接受任何参数。</p>
<p><strong>用法</strong></p>
<p>复制代码 代码如下:</p>
<p>&lt;?php if ( is_user_logged_in() ) { &#8230; } ?&gt;<br />
<strong>示例 </strong><br />
根据当前访问者的登录情况，使用is_user_logged_in()函数在主题文件中展示不同输出结果。</p>
<p>复制代码 代码如下:</p>
<p>&lt;?php<br />
if ( is_user_logged_in() ) {<br />
echo &#8216;Welcome, registered user!&#8217;;<br />
} else {<br />
echo &#8216;Welcome, visitor!&#8217;;<br />
}<br />
?&gt;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>wordpress常用函数-get_currentuserinfo()</title>
		<link>https://www.3code.cn/wordpress%e5%b8%b8%e7%94%a8%e5%87%bd%e6%95%b0-get_currentuserinfo/</link>
		
		<dc:creator><![CDATA[寒林]]></dc:creator>
		<pubDate>Mon, 06 Jun 2011 07:29:08 +0000</pubDate>
				<category><![CDATA[WORDPRESS主题技术]]></category>
		<category><![CDATA[wordpress函数]]></category>
		<guid isPermaLink="false">https://www.3code.cn/?p=2701</guid>

					<description><![CDATA[wordpress常用函数-get_currentuserinfo()]]></description>
										<content:encoded><![CDATA[<h2>常用函数-get_currentuserinfo()</h2>
<h3>说明</h3>
<p>检索当前登录用户的相关信息，并将信息置入$userdata全局变量。函数属性直接映射到数据库（参见 <a title="Database Description" href="http://codex.wordpress.org/Database_Description#Table:_wp_users">Database Description</a>）中的wp_usrs表格。</p>
<p>同样也将个体属性放置到以下独立全局变量中：</p>
<ul>
<li>$user_login</li>
<li>$user_level</li>
<li>$user_ID</li>
<li>$user_email</li>
<li>$user_url（用户在用户资料中输入的网址）</li>
<li>$user_pass_md5 （用户密码的md5 hash——一种几乎无法解密（不是完全无法解密）的编码，可比较输入提示口令与实际用户密码的不同）</li>
<li>$display_name（用户名，根据&#8217;How to display name&#8217;用户选项结果进行显示）</li>
</ul>
<h3>用法</h3>
<p>&lt;?php get_currentuserinfo(); ?&gt;</p>
<h3>示例</h3>
<h4>缺省用法</h4>
<p>调用get_currentuserinfo()将当前用户信息放入$userdata，可用成员变量在$userdata中检索用户信息。</p>
<pre>&lt;?php global $current_user;        
      get_currentuserinfo();          

      echo('Username: ' . $current_user-&gt;user_login . "\n");    
      echo('User email: ' . $current_user-&gt;user_email . "\n");  
      echo('User level: ' . $current_user-&gt;user_level . "\n");  
      echo('User first name: ' . $current_user-&gt;user_firstname . "\n");   
      echo('User last name: ' . $current_user-&gt;user_lastname . "\n");  
      echo('User display name: ' . $current_user-&gt;display_name . "\n");    
      echo('User ID: ' . $current_user-&gt;ID . "\n");  
?&gt;</pre>
<p> </p>
<p>Username: Zedd<br />
User email: my@email.com<br />
User level: 10<br />
User first name: John<br />
User last name: Doe<br />
User display name: John Doe</p>
<p>User ID: 1</p>
<h4>使用独立全局变量</h4>
<p>用户资料大多存放在单个全局变量中，可直接访问。</p>
<pre>&lt;?php global $display_name , $user_email;        
      get_currentuserinfo();          

      echo($display_name . "'s email address is: " . $user_email);  
?&gt;</pre>
<p>Zedd&#8217;s email address is: fake@email.com</p>
<p>注意：<em>$display_name</em>似乎无法在2.5以上版本中运行。<em>$user_login</em>运行良好。</p>
<pre>&lt;?php global $user_login , $user_email;        
      get_currentuserinfo();          

      echo($user_login . "'s email address is: " . $user_email);  
?&gt;</pre>
<h3>参数</h3>
<p>该函数不接受任何参数。</p>
<p>检查当前是否有已登录用户，执行以下代码：</p>
<pre>&lt;?php global $user_ID;        
      get_currentuserinfo();          

      if ('' == $user_ID) {           
         //no user logged in        
      }  
?&gt;</pre>
<p>下面仍然是一个IF STATEMENT示例，用在侧边条中，参照<a title="http://www.kriesi.at/archives/wordpress-plugin-my-favorite-posts" href="http://www.kriesi.at/archives/wordpress-plugin-my-favorite-posts">ttp://www.kriesi.at/archives/wordpress-plugin-my-favorite-posts</a> 中的&#8221;My Fav&#8221;插件。</p>
<pre>&lt;?php if ( $user_ID ) { ?&gt;  
&lt;!-- enter info that logged in users will see --&gt;  
&lt;!-- in this case im running a bit of php to a plugin --&gt;    

&lt;?php mfp_display(); ?&gt;    

&lt;?php } else {   ?&gt;  
&lt;!-- here is a paragraph that is shown to anyone not logged in --&gt;   

&lt;p&gt;By &lt;a href="&lt;?php bloginfo('url'); ?&gt;/wp-register.php"&gt;registering&lt;/a&gt;, you can save your favorite 
posts for future reference.&lt;/p&gt;    

&lt;?php } ?&gt;</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>wordpress判断分类下有没有子类</title>
		<link>https://www.3code.cn/wordpress%e5%88%a4%e6%96%ad%e5%88%86%e7%b1%bb%e4%b8%8b%e6%9c%89%e6%b2%a1%e6%9c%89%e5%ad%90%e7%b1%bb/</link>
		
		<dc:creator><![CDATA[寒林]]></dc:creator>
		<pubDate>Sat, 07 May 2011 14:57:33 +0000</pubDate>
				<category><![CDATA[WORDPRESS主题技术]]></category>
		<category><![CDATA[wordpress函数]]></category>
		<category><![CDATA[wordpress分类]]></category>
		<guid isPermaLink="false">https://www.3code.cn/?p=2549</guid>

					<description><![CDATA[wordpress判断分类下有没有子类]]></description>
										<content:encoded><![CDATA[<p><strong>假设分类的id为 $catID，那么可以用以下函数判断是否有子类</strong></p>
<p>&lt;?</p>
<p>if ( get_category_children($catID) != &#8220;&#8221; ) {<br />
   // 有子类<br />
}<br />
else {<br />
   // 没有子类<br />
}</p>
<p>?&gt;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>常用函数-get_post()</title>
		<link>https://www.3code.cn/%e5%b8%b8%e7%94%a8%e5%87%bd%e6%95%b0-get_post/</link>
					<comments>https://www.3code.cn/%e5%b8%b8%e7%94%a8%e5%87%bd%e6%95%b0-get_post/#comments</comments>
		
		<dc:creator><![CDATA[寒林]]></dc:creator>
		<pubDate>Fri, 07 Jan 2011 02:33:56 +0000</pubDate>
				<category><![CDATA[WORDPRESS主题技术]]></category>
		<category><![CDATA[wordpress函数]]></category>
		<guid isPermaLink="false">https://www.3code.cn/?p=2417</guid>

					<description><![CDATA[常用函数-get_post()]]></description>
										<content:encoded><![CDATA[<h2>常用函数-get_post()</h2>
<h3>说明</h3>
<p>读取文章编号（ID），将文章记录返回数据库。用户可通过$output参数指定结果的返回方式。</p>
<h3>用法</h3>
<p>&lt;?php get_post($post, $output); ?&gt;</p>
<h3>示例</h3>
<p>获取编号（ID）为7的文章标题：</p>
<p>&lt;?php<br />
$my_id = 7;<br />
$post_id_7 = get_post($my_id);<br />
$title = $post_id_7-&gt;post_title;<br />
?&gt;</p>
<p>也可以指定$output参数：</p>
<p>&lt;?php<br />
$my_id = 7;<br />
$post_id_7 = get_post($my_id, ARRAY_A);<br />
$title = $post_id_7[&#8216;post_title&#8217;];<br />
?&gt;</p>
<p>&lt;?php<br />
##    Correct: pass a dummy variable as post_id<br />
$the_post = &amp; get_post( $dummy_id = 7 );</p>
<p>##    Incorrect: literal integer as post_id<br />
$the_post = &amp; get_post( 7 );<br />
//    Fatal error: &#8216;Only variables can be passed for reference&#8217; or &#8216;Cannot pass parameter 1 by reference&#8217;<br />
?&gt;</p>
<h3>参数</h3>
<p><strong>$post</strong></p>
<p>（整数）（必需）需要获取的文章的编号（ID）。必须传递一个含有整数的变量（如$id）。仅传递整数会引发严重错误（<em>只能传递变量以供参考</em>或<em>不允许传递值为1的参数</em>）。</p>
<p>默认值：None</p>
<p><strong>$output</strong></p>
<p>（字符）（可选）如何显示返回结果</p>
<ul>
<li><em>OBJECT </em>—— 返回对象</li>
<li><em>ARRAY_A</em> —— 返回值字段名称的关联数组</li>
<li><em>ARRAY_N </em>—— 返回字段值的数值数组</li>
</ul>
<p>默认值：OBJECT</p>
<h3>返回</h3>
<p>返回的字段为：</p>
<p><strong>ID</strong></p>
<p>（整数）文章编号</p>
<p><strong>post_author</strong></p>
<p>(整数）文章作者的编号</p>
<p><strong>post_data</strong></p>
<p>(字符）文章发表的日期和时间（YYYY-MM-DD HH-MM-SS)</p>
<p><strong>post_data_gmt</strong></p>
<p>（字符）文章发表的格林尼治标准时间（GMT） （YYYY-MM-DD HH-MM-SS)</p>
<p><strong>post_content</strong></p>
<p>（字符）文章内容</p>
<p><strong>post_title</strong></p>
<p>（字符）文章标题</p>
<p><strong>post_category</strong></p>
<p>（整数）文章类别的编号。注意：该值在WordPress 2.1之后的版本总为0。定义文章的类别时可使用 get_the_category()函数。</p>
<p><strong>post_excerpt</strong></p>
<p>（字符）文章摘要</p>
<p><strong>post_status</strong></p>
<p>(字符）文章状态（<tt>publish|pending|draft|private|static|object|attachment|inherit|future</tt>）</p>
<p><strong>comment_status</strong></p>
<p>（字符）评论状态（<tt>open|closed|registered_only</tt>）</p>
<p><strong>ping_status</strong></p>
<p>（字符）pingback/trackback状态（<tt>open|closed</tt>）</p>
<p><strong>post_password</strong></p>
<p>(字符）文章密码</p>
<p><strong>post_name</strong></p>
<p>(字符）文章的URL嵌套</p>
<p><strong>to_ping</strong></p>
<p>(字符）要引用的URL链接</p>
<p><strong>pinged</strong></p>
<p>（字符）引用过的链接</p>
<p><strong>post_modified</strong></p>
<p>(字符）文章最后修改时间（YYYY-MM-DD HH-MM-SS)</p>
<p><strong>post_modified_gmt</strong></p>
<p>(字符）文章最后修改GMT时间（YYYY-MM-DD HH-MM-SS)</p>
<p><strong>post_content_filtered</strong></p>
<p>(字符）</p>
<p><strong>post_parent</strong></p>
<p>(整数）父级文章编号（供附件等）</p>
<p><strong>guid</strong></p>
<p>（字符）文章的一个链接。注意：不能将GUID作为永久链接（虽然在2.5之前的版本中它的确被当作永久链接），也不能将它作为文章的可用链接。GUID是一种独有的标识符，只是目前恰巧成为文章的一个链接。</p>
<p><strong>menu_order</strong></p>
<p>（整数）</p>
<p><strong>post_type</strong></p>
<p>（字符）（日志 | 页面 | 附件）</p>
<p><strong>post_mime_type</strong></p>
<p>(字符）Mime类型（供附件等）</p>
<p><strong>comment_count</strong></p>
<p>（整数）评论总数</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.3code.cn/%e5%b8%b8%e7%94%a8%e5%87%bd%e6%95%b0-get_post/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>wordpress wp_logout_url登出函数</title>
		<link>https://www.3code.cn/wordpress-wp_logout_url/</link>
		
		<dc:creator><![CDATA[寒林]]></dc:creator>
		<pubDate>Fri, 24 Dec 2010 03:19:21 +0000</pubDate>
				<category><![CDATA[WORDPRESS主题技术]]></category>
		<category><![CDATA[wordpress函数]]></category>
		<guid isPermaLink="false">https://www.3code.cn/?p=2399</guid>

					<description><![CDATA[wordpress wp_logout_url登出函数]]></description>
										<content:encoded><![CDATA[<p><strong>用法：<br />
</strong><span style="COLOR: #0000bb">&lt;?php </span><span style="COLOR: #007700">echo </span><span style="COLOR: #0000bb">wp_logout_url</span><span style="COLOR: #007700">( </span><span style="COLOR: #0000bb">$redirect </span><span style="COLOR: #007700">); </span><span style="COLOR: #0000bb">?&gt;</span></p>
<p><strong>参数：</strong><br />
redirect<br />
(string) (可选) 当登出的时候转到的URL<br />
默认无</p>
<p><strong>示例：<br />
</strong>默认跳转页： <br />
&lt;a href=&#8221;&lt;?php echo wp_logout_url(); ?&gt;&#8221; title=&#8221;Logout&#8221;&gt;Logout&lt;/a&gt;</p>
<p>跳转到当前页：<br />
&lt;a href=&#8221;&lt;?php echo wp_logout_url( get_permalink() ); ?&gt;&#8221; title=&#8221;Logout&#8221;&gt;Logout&lt;/a&gt;</p>
<p>跳转到首页：<br />
&lt;a href=&#8221;&lt;?php echo wp_logout_url( home_url() ); ?&gt;&#8221; title=&#8221;Logout&#8221;&gt;Logout&lt;/a&gt;</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
<strong>一些常用wordpress判断函数：<br />
</strong>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
is_single()<br />
When any single Post page is being displayed. 判断是否是具体文章的页面<br />
is_single(’17′)<br />
When Post 17 is being displayed as a single Post. 判断是否是具体文章（id=17）的页面<br />
is_single(’Beef Stew’)<br />
When the Post with Title “Beef Stew” is being displayed as a single Post. 判断是否是具体文章（标题判断）的页面<br />
is_single(’beef-stew’)<br />
When the Post with Post Slug “beef-stew” is being displayed as a single Post. 判断是否是具体文章（slug判断）的页面</p>
<p>comments_open()<br />
When comments are allowed for the current Post being processed in the WordPress Loop. 是否留言开启<br />
pings_open()<br />
When pings are allowed for the current Post being processed in the WordPress Loop. 是否开启ping</p>
<p>is_page()<br />
When any Page is being displayed. 是否是页面<br />
is_page(’42′)<br />
When Page 42 is being displayed. 同single，id判断，即是否是id为42的页面<br />
is_page(’About Me’)<br />
When the Page with Title “About Me” is being displayed. title判断<br />
is_page(’about-me’)<br />
When the Page with Page Slug “about-me” is being displayed. slug判断</p>
<p>is_category()<br />
When any Category archive page is being displayed. 是否是分类<br />
is_category(’6′)<br />
When the archive page for Category 6 is being displayed. 同single，id判断，即是否是id为6的分类<br />
is_category(’Cheeses’)<br />
When the archive page for the Category with Name “Cheeses” is being displayed. title判断<br />
is_category(’cheeses’)<br />
When the archive page for the Category with Category Slug “cheeses” is being displayed. slug判断<br />
in_category(’5′)<br />
Returns true if the current post is in the specified category id. read more (http://codex.wordpress.org/Template_Tags/in_category) 判断当前的文章是否属于分类5</p>
<p>is_author()<br />
When any Author page is being displayed. 将所有的作者的页面显示出来<br />
is_author(’1337′)<br />
When the archive page for Author number 1337 is being displayed. 显示author number为1337的页面<br />
is_author(’Elite Hacker’)<br />
When the archive page for the Author with Nickname “Elite Hacker” is being displayed. 通过昵称来显示当前作者的页面<br />
is_author(’elite-hacker’)<br />
When the archive page for the Author with Nicename “elite-hacker” is being displayed.</p>
<p>下面是通过不同的判断实现以年、月、日、时间等方式来显示归档<br />
is_date()<br />
When any date-based archive page is being displayed (i.e. a monthly, yearly, daily or time-based archive).<br />
is_year()<br />
When a yearly archive is being displayed.<br />
is_month()<br />
When a monthly archive is being displayed.<br />
is_day()<br />
When a daily archive is being displayed.<br />
is_time()<br />
When an hourly, “minutely”, or “secondly” archive is being displayed.</p>
<p>判断当前是否是归档页面<br />
is_archive()<br />
When any type of Archive page is being displayed. Category, Author and Date based pages are all types of Archives.</p>
<p>判断是否是搜索<br />
is_search()<br />
When a search result page archive is being displayed.</p>
<p>判断页面是否404<br />
is_404()<br />
When a page displays after an “HTTP 404: Not Found” error occurs.</p>
<p>判断是否翻页，比如你当前的blog是http://domain.com 显示http://domain.com?paged=2的时候，这个判断将返回真，通过这个函数可以配合is_home来控制某些只能在首页显示的界面，<br />
例如：if(is_home() &amp;&amp; !is_paged() )<br />
is_paged()<br />
When the page being displayed is “paged”. This refers to an archive or the main page being split up over several pages. This does not refer to a Post or Page whose content has been divided into pages using the QuickTag.</p>
<p>is_attachment()<br />
When an attachment document to a post or Page is being displayed. An attachment is an image or other file uploaded through the post editor’s upload utility. Attachments can be displayed on their own ‘page’ or template. For more information, see Using Image and File Attachments.</p>
<p>is_feed()<br />
When the site requested is a Syndication. This tag is not typically used by users; it is used internally by WordPress and is available for Plugin Developers.</p>
<p>is_trackback()<br />
When the site requested is WordPress’ hook into its Trackback engine. This tag is not typically used by users; it is used internally by WordPress and is available for Plugin Developers.</p>
<p>is_user_logged_in()<br />
判断是否登录</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>query_posts详细应用教程</title>
		<link>https://www.3code.cn/query_posts%e8%af%a6%e7%bb%86%e5%ba%94%e7%94%a8%e6%95%99%e7%a8%8b/</link>
		
		<dc:creator><![CDATA[寒林]]></dc:creator>
		<pubDate>Tue, 14 Dec 2010 08:59:48 +0000</pubDate>
				<category><![CDATA[WORDPRESS主题技术]]></category>
		<category><![CDATA[wordpress函数]]></category>
		<guid isPermaLink="false">https://www.3code.cn/?p=2386</guid>

					<description><![CDATA[query_posts详细应用教程该标签可决定哪些文章出现在WordPress主循环（loop）中。该标签接收大量参数，格式与URL中的参数格式相同（如p=4表示ID为4的文章）。为什么非要更改从URL中生成的查询语句呢？你完全可以通过结合博客文章与页面逻辑（如条件标签）来定制博客文章的样式——而无需更改任何URL。]]></description>
										<content:encoded><![CDATA[<h3>说明</h3>
<p>该标签可决定哪些文章出现在WordPress主循环（loop）中。该标签接收大量参数，格式与URL中的参数格式相同（如p=4表示ID为4的文章）。</p>
<p>为什么非要更改从URL中生成的查询语句呢？你完全可以通过结合博客文章与页面逻辑（如条件标签）来定制博客文章的样式——而无需更改任何URL。</p>
<p>常见用途：</p>
<ul>
<li>仅在博客主页上显示一篇文章（通过设置&gt;阅读进行设置）</li>
<li>显示某一特定时间段内发表的所有文章</li>
<li>在主页显示近期发表文章</li>
<li>更改文章排列顺序</li>
<li>仅显示某一分类目录中的文章</li>
<li>排除一个或多个分类</li>
</ul>
<h3>重要提示</h3>
<p>query_posts函数仅用于修改主页循环（Loop），而不是一种在页面上生成次级循环的手段。如果你希望在主循环外另外生成循环，应该新建独立的WP_Query对象，用这些对象生成循环。在主循环外的循环上使用query_posts会导致主循环运行偏差，并可能在页面上显示出你不希望看到的内容。</p>
<p>query_posts函数会改写并取代页面的主查询。为谨慎起见，请不要将query_posts用作其它用途。</p>
<h3>用法</h3>
<p>&lt;?php</p>
<p>//The Query<br />
query_posts(&#8216;posts_per_page=5&#8217;);</p>
<p>//The Loop<br />
if ( have_posts() ) : while ( have_posts() ) : the_post();<br />
..<br />
endwhile; else:<br />
..<br />
endif;</p>
<p>//Reset Query<br />
wp_reset_query();</p>
<p>?&gt;</p>
<p><strong>用法提示</strong></p>
<p>在主循环开始前，对你的某个模板文件的query_posts()安排一个调用。wp_query对象会利用参数生成新的SQL查询。当你开始调用时，WordPress会忽略通过URL接收到的其它参数（如页面编号或分类）。如果你希望保留这些信息，可以在对query_posts()的调用中使用$query_string全局变量。</p>
<p>例如，要设置文章的显示顺序而不影响查询字符串的剩余部分，可以将以下代码添加到主循环（loop）之前：</p>
<pre>global $query_string;  
query_posts($query_string . "&amp;order=ASC");</pre>
<p>以这种方式使用query_posts时，参数所引用的部分必须以&amp;符号开头。</p>
<h3>示例</h3>
<p><a name="exclude"><strong>从博客主页上排除某些分类</strong></a></p>
<p>将以下代码添加到index.php文件中，使主页显示的文章可以来自除分类3以外的任何分类。</p>
<p>&lt;?php<br />
if (is_home()) {<br />
query_posts(&#8220;cat=-3&#8221;);<br />
}<br />
?&gt;</p>
<p>你也可以多排除几个分类。</p>
<p>&lt;?php<br />
if (is_home()) {<br />
query_posts(&#8220;cat=-1,-2,-3&#8221;);<br />
}<br />
?&gt;</p>
<p><strong>检索指定文章</strong></p>
<p>用以下语句检索某篇指定文章：</p>
<p>&lt;?php<br />
// retrieve one post with an ID of 5<br />
query_posts(&#8216;p=5&#8217;);<br />
?&gt;</p>
<p>如果你希望在查询语句中使用Read More功能，请将全局变量$more设为0。</p>
<p>&lt;?php<br />
// retrieve one post with an ID of 5<br />
query_posts(&#8216;p=5&#8217;);</p>
<p>global $more;<br />
// set $more to 0 in order to only get the first part of the post<br />
$more = 0;</p>
<p>// the Loop<br />
while (have_posts()) : the_post();<br />
// the content of the post<br />
the_content(&#8216;Read the full post ?&#8217;);<br />
endwhile;<br />
?&gt;</p>
<p><strong>检索指定页面</strong></p>
<p>用以下语句检索某篇指定页面：</p>
<p>&lt;?php<br />
query_posts(&#8216;page_id=7&#8217;); //retrieves page 7 only<br />
?&gt;</p>
<p>或者</p>
<p>&lt;?php<br />
query_posts(&#8216;pagename=about&#8217;); //retrieves the about page only<br />
?&gt;</p>
<p>检索子页面时，需要提供子页面及其父页面的别名，用斜线隔开两者。例如：</p>
<p>&lt;?php<br />
query_posts(&#8216;pagename=parent/child&#8217;); // retrieve the child page of a parent<br />
?&gt;</p>
<p><strong>给query_posts传递变量</strong></p>
<p>有两种方法可以给给查询传递变量，你可以根据自己的需求从中选择一种。使用时，将代码添加到循环中：</p>
<p><strong>示例1</strong></p>
<p>在这个例子中，我们在运行查询语句前先连结所有查询。首先赋值变量，然后连结变量并运行。这里我们要从别处引入一个分类变量。</p>
<p>&lt;?php<br />
$categoryvariable=$cat; // assign the variable as current category<br />
$query= &#8216;cat=&#8217; . $categoryvariable. &#8216;&amp;orderby=date&amp;order=ASC&#8217;; // concatenate the query<br />
query_posts($query); // run the query<br />
?&gt;</p>
<p><strong>示例2</strong></p>
<p>这个示例将使用双引号来告诉PHP将引号中的内容当成表达式。在下面的例子中，我们要获取当前月份、年份时间，然后让query_posts获取当前月/年的文章，并且以升序方式在页面最上方显示发表日期最早的文章。</p>
<p>&lt;?php<br />
$current_month = date(&#8216;m&#8217;);<br />
$current_year = date(&#8216;Y&#8217;);</p>
<p>query_posts(&#8220;cat=22&amp;year=$current_year&amp;monthnum=$current_month&amp;order=ASC&#8221;);<br />
?&gt;<br />
&lt;!&#8211; put your loop here &#8211;&gt;</p>
<p><strong>示例3</strong></p>
<p>该示例说明了怎样生成一个完整的文章分页列表。我们可以用默认的$query_string来命令query_posts给我们显示一个完整的文章列表。也可以将posts_per_page查询语句从-1改成你希望在每页显示的文章数。在后面这种情况下，你可以用posts_nav_link 来导航所生成的存档。</p>
<p>&lt;?php<br />
query_posts($query_string.&#8217;&amp;posts_per_page=-1&#8242;);<br />
while(have_posts()) { the_post();<br />
&lt;!&#8211; put your loop here &#8211;&gt;<br />
}<br />
?&gt;</p>
<p><strong>示例4</strong></p>
<p>如果你不需要使用$query_string变量，可以在一些复杂的情况下使用一个更简单易读的方法。这个方法就是，将参数放入数组。那么通过下面的代码，也可以生成示例2中的查询：</p>
<p>query_posts(array(<br />
&#8216;cat&#8217; =&gt; 22,<br />
&#8216;year&#8217; =&gt; $current_year,<br />
&#8216;monthnum&#8217; =&gt; $current_month,<br />
&#8216;order&#8217; =&gt; &#8216;ASC&#8217;,<br />
));</p>
<p>现在你可以看到，所有变量都独立成行，更加便于阅读。</p>
<p><strong>保留原始查询</strong></p>
<p>如果你希望保留原始查询，可以将原始查询数组整合到参数数组中：</p>
<p>global $wp_query;<br />
query_posts(<br />
array_merge(<br />
array(&#8216;cat&#8217; =&gt; 1),<br />
$wp_query-&gt;query<br />
)<br />
);</p>
<h3>参数</h3>
<p>这里并没有列出完整的参数列表。我们在这里介绍这些参数，只是为了让你多了解一些关于如何设置查询的信息。</p>
<h4>分类参数</h4>
<p>只显示特定分类下的文章。</p>
<ul>
<li>cat —— 必须使用分类ID</li>
<li>category_name</li>
<li>category_and —— 必须使用分类ID</li>
<li>category_in —— 必须使用分类ID</li>
<li>category_not_in —— 必须使用分类ID</li>
</ul>
<p><strong>根据ID显示单个分类</strong></p>
<p>只显示来自某一个分类目录ID（以及该分类目录下的子分类目录）的文章：</p>
<pre>query_posts('cat=4');</pre>
<p><strong>根据分类名称显示单个分类</strong></p>
<p>只显示来自某一个分类名称下的文章：</p>
<pre>query_posts('category_name=Staff Home');</pre>
<p><strong>根据ID显示多个分类</strong></p>
<p>显示来自若干指定分类目录ID下的文章：</p>
<pre>query_posts('cat=2,6,17,38');</pre>
<p><strong>排除某一分类中的文章</strong></p>
<p>显示除某一分类文章外的所有文章，被排除的分类ID以减号（&#8217;-&#8216;）作为前缀。</p>
<pre>query_posts('cat=-3');</pre>
<p>以上代码删除ID为3的分类中的文章。</p>
<p><strong>处理多个分类</strong></p>
<p>显示隶属于多个分类的文章。下面的代码可展示同时属于分类2和分类6的文章：</p>
<pre>query_posts(array('category__and' =&gt; array(2,6)));</pre>
<p>如果希望显示分类2或分类6中的文章，可以使用上面介绍的cat，也可以使用category_in函数 （注意这里不会显示分类下子分类中的文章） ：</p>
<pre>query_posts(array('category__in' =&gt; array(2,6)));</pre>
<p>可以用下面这种方式排除多个分类中的文章：</p>
<pre>query_posts(array('category__not_in' =&gt; array(2,6)));</pre>
<h4>标签参数</h4>
<p>显示特定标签下的文章。</p>
<ul>
<li>tag —— 必须使用标签ID</li>
<li>tag_id —— 必须使用标签ID</li>
<li>tag_and —— 必须使用标签ID</li>
<li>tag_in —— 必须使用标签ID</li>
<li>tag_not_in —— 必须使用标签ID</li>
<li>tag_slug_and ——必须使用标签ID</li>
<li>tag_slug_in ——必须使用标签ID</li>
</ul>
<p><strong>获取某一标签中的文章</strong></p>
<pre>query_posts('tag=cooking');</pre>
<p><strong>获取若干标签中任一标签中的文章</strong></p>
<pre>query_posts('tag=bread+baking+recipe');</pre>
<p><strong>多个标签</strong></p>
<p>显示同时属于ID为37和47的标签下的文章：</p>
<pre>query_posts(array('tag__and' =&gt; array(37,47));</pre>
<p>若要显示ID为为37或47的标签下的文章，可以使用tag参数，也可以用tag_in：</p>
<pre>query_posts(array('tag__in' =&gt; array(37,47));</pre>
<p>显示的文章既不属于标签37，也不属于标签47：</p>
<pre>query_posts(array('tag__not_in' =&gt; array(37,47));</pre>
<p>tag_slug_in与tag_slug_and工作方式几乎一致，不同之处在于相匹配的别名不同。</p>
<h4>作者参数</h4>
<p>你也可以根据作者来选择文章。</p>
<ul>
<li>author=3</li>
<li>author=-3 ——排除ID为3的作者所发表的文章</li>
<li>author_name=Harriet</li>
</ul>
<p>注意：author_name运行在user_nicename字段上，同时author运行在author id字段上。</p>
<p>显示ID为1的作者所发表的所有页面，以标题顺序排列页面，页面列表上方无置顶文章：</p>
<pre>query_posts('caller_get_posts=1&amp;author=1&amp;post_type=page&amp;post_status=publish&amp;orderby=title&amp;order=ASC');</pre>
<h4>文章&amp;页面参数</h4>
<p>检索单篇文章或页面。</p>
<ul>
<li>&#8216;p&#8217; =&gt; 27 —— 通过文章ID显示该文章</li>
<li>&#8216;name&#8217; =&gt; &#8216;about-my-life&#8217; —— 对某篇文章的查询，查询中含有文章别名</li>
<li>&#8216;page_id&#8217; =&gt; 7 —— 对ID为7的页面的查询</li>
<li>&#8216;pagename&#8217; =&gt; &#8216;about&#8217; —— 注意，这不是页面标题，而是页面路径</li>
<li>用&#8217;posts_per_page&#8217; =&gt; 1 &#8211; use &#8216;posts_per_page&#8217; =&gt; 3 展示3篇文章。用&#8217;posts_per_page&#8217; =&gt; -1展示所有文章</li>
<li>&#8216;showposts&#8217; =&gt; 1 &#8211; use &#8216;showposts&#8217; =&gt; 3 展示3篇文章。用&#8217;showposts&#8217; =&gt; -1展示所有文章。已弃用。</li>
<li>&#8216;post__in&#8217; =&gt; array(5,12,2,14,7) —— 指定希望检索的文章ID</li>
<li>&#8216;post__not_in&#8217; =&gt; array(6,2,8) ——排除不希望检索的文章ID</li>
<li>&#8216;post_type&#8217; =&gt; &#8216;page&#8217; ——返回页面；默认值为post；可用值包括any, attachment, page, post或revision。any可检索到除修订版外的所有页面类型。</li>
<li>&#8216;post_status&#8217; =&gt; &#8216;publish&#8217; —— 返回已发布页面。可用值还包括pending, draft, future, private, trash。关于inherit请见get_children。trash状态新增于WordPress 2.9。</li>
<li>&#8216;post_parent&#8217; =&gt; 93 —— 返回页面93的子页面。</li>
</ul>
<h4>置顶文章参数</h4>
<p>置顶文章功能引入于WordPress 2.7。在查询中，被设为“置顶”的文章会显示在其它文章之前，除非该文章已经被<em>caller_get_posts=1</em>参数排除。</p>
<ul>
<li>array(&#8216;post__in&#8217;=&gt;get_option(&#8216;sticky_posts&#8217;)) —— 返回所有置顶文章的数组</li>
<li>caller_get_posts=1 —— 排除返回的文章上方的置顶文章，但在返回文章列表时，以自然顺序将曾经置顶的文章安插在列表中。</li>
</ul>
<p><strong>返回第一篇置顶文章</strong></p>
<p>$sticky=get_option(&#8216;sticky_posts&#8217;) ;<br />
query_posts(&#8216;p=&#8217; . $sticky[0]);</p>
<p>或</p>
<p>$args = array(<br />
&#8216;posts_per_page&#8217; =&gt; 1,<br />
&#8216;post__in&#8217; =&gt; get_option(&#8216;sticky_posts&#8217;),<br />
&#8216;caller_get_posts&#8217; =&gt; 1<br />
);<br />
query_posts($args);</p>
<p>注意：第二种方法只能返回最新发表的置顶文章；若当前无置顶文章，返回最新发表文章。</p>
<p><strong>返回第一篇置顶文章；若无，则不返回任何内容</strong></p>
<p>$sticky = get_option(&#8216;sticky_posts&#8217;);<br />
$args = array(<br />
&#8216;posts_per_page&#8217; =&gt; 1,<br />
&#8216;post__in&#8217; =&gt; $sticky,<br />
&#8216;caller_get_posts&#8217; =&gt; 1<br />
);<br />
query_posts($args);<br />
if($sticky[0]) {<br />
// insert here your stuff&#8230;<br />
}</p>
<p><strong>从查询中排除所有置顶文章</strong></p>
<pre>query_posts(array("post__not_in" =&gt;get_option("sticky_posts")));</pre>
<p><strong>返回某一分类下所有文章，但不在文章列表上方显示置顶文章。所有设为“置顶”的文章以正常顺序（如日期顺序）显示</strong></p>
<pre>query_posts('caller_get_posts=1&amp;posts_per_page=3&amp;cat=6');</pre>
<p><strong>返回某一分类下所有文章，完全不显示置顶文章，保留分页</strong></p>
<p>&lt;?php<br />
$paged = (get_query_var(&#8216;paged&#8217;)) ? get_query_var(&#8216;paged&#8217;) : 1;<br />
$sticky=get_option(&#8216;sticky_posts&#8217;);<br />
$args=array(<br />
&#8216;cat&#8217;=&gt;3,<br />
&#8216;caller_get_posts&#8217;=&gt;1,<br />
&#8216;post__not_in&#8217; =&gt; $sticky,<br />
&#8216;paged&#8217;=&gt;$paged,<br />
);<br />
query_posts($args);<br />
?&gt;</p>
<h4>时间参数</h4>
<p>检索特定时间段内发表的文章。</p>
<ul>
<li>hour= -hour （时，-范围从0到23）</li>
<li>minute= &#8211; minute （分，-范围从0到60）</li>
<li>second= &#8211; second （秒，-范围从0到60）</li>
<li>day= &#8211; day of the month （日，-范围从1到31）</li>
<li>monthnum= &#8211; month number （月，-范围从1到12）</li>
<li>year= &#8211; 4 digit year (年，如2009)</li>
<li>w= &#8211; week of the year（一年中的第几周，-范围从0到53），使用 MySQL WEEK command Mode=1命令</li>
</ul>
<p><strong>返回最近发表的文章</strong></p>
<pre>$today = getdate();  
query_posts('year=' .$today["year"] .'&amp;monthnum=' .$today["mon"] .'&amp;day=' .$today["mday"] );</pre>
<p><strong>返回12月20日发表的文章</strong></p>
<pre>query_posts(monthnum=12&amp;day=20' );</pre>
<p><strong>返回2009年3月1日到3月15日之间发表的文章</strong></p>
<p>&lt;?php<br />
//based on Austin Matzko&#8217;s code from wp-hackers email list<br />
function filter_where($where = &#8221;) {<br />
//posts for March 1 to March 15, 2009<br />
$where .= &#8221; AND post_date &gt;= &#8216;2009-03-01&#8217; AND post_date &lt; &#8216;2009-03-16&#8242;&#8221;;<br />
return $where;<br />
}<br />
add_filter(&#8216;posts_where&#8217;, &#8216;filter_where&#8217;);<br />
query_posts($query_string);<br />
?&gt;</p>
<p><strong>返回最近30天内发表的文章</strong></p>
<p>&lt;?php<br />
//based on Austin Matzko&#8217;s code from wp-hackers email list<br />
function filter_where($where = &#8221;) {<br />
//posts in the last 30 days<br />
$where .= &#8221; AND post_date &gt; &#8216;&#8221; . date(&#8216;Y-m-d&#8217;, strtotime(&#8216;-30 days&#8217;)) . &#8220;&#8216;&#8221;;<br />
return $where;<br />
}<br />
add_filter(&#8216;posts_where&#8217;, &#8216;filter_where&#8217;);<br />
query_posts($query_string);<br />
?&gt;</p>
<p><strong>返回过去30天到过去60天内发表的文章</strong></p>
<p>&lt;?php<br />
//based on Austin Matzko&#8217;s code from wp-hackers email list<br />
function filter_where($where = &#8221;) {<br />
//posts 30 to 60 days old<br />
$where .= &#8221; AND post_date &gt;= &#8216;&#8221; . date(&#8216;Y-m-d&#8217;, strtotime(&#8216;-60 days&#8217;)) . &#8220;&#8216;&#8221; . &#8221; AND post_date &lt;= &#8216;&#8221; . date(&#8216;Y-m-d&#8217;, strtotime(&#8216;-30 days&#8217;)) . &#8220;&#8216;&#8221;;<br />
return $where;<br />
}<br />
add_filter(&#8216;posts_where&#8217;, &#8216;filter_where&#8217;);<br />
query_posts($query_string);<br />
?&gt;</p>
<h4>分页参数</h4>
<ul>
<li>paged=2 ——显示点击“较早的日志”链接后出现在第二页中的文章</li>
<li>posts_per_page=10 —— 每页所显示的文章数量；若值为-1，显示所有文章。</li>
<li>order=ASC —— 按时间顺序显示文章，若值为DESC则按逆向时间顺序显示文章（默认）</li>
</ul>
<h4>offset（偏移）参数</h4>
<p>通过offset参数，你可以移除或忽略正常情况下被查询集中的一篇或多篇初始文章。</p>
<p>以下显示最近一篇文章之后的5篇文章：</p>
<pre>query_posts('posts_per_page=5&amp;offset=1');</pre>
<h4>排序参数</h4>
<ul>
<li>orderby=author</li>
<li>orderby=date</li>
<li>orderby=category ——注意：该参数不能用于WordPress 2.8，可能已经被废止</li>
<li>orderby=title</li>
<li>orderby=modified</li>
<li>orderby=menu_order</li>
<li>orderby=parent</li>
<li>orderby=ID</li>
<li>orderby=rand</li>
<li>orderby=meta_value —— meta_key=some value语句也应出现在查询参数中</li>
<li>orderby=none &#8211; no order —— (新增于 WP 2.8)</li>
<li>orderby=comment_count ——（新增于 WP 2.9)</li>
</ul>
<h4>顺序参数</h4>
<p>决定以升序或降序排列<strong>排序参数</strong></p>
<ul>
<li>order=ASC —— 升序，从最低值到最高值</li>
<li>order=DESC —— 降序，从最高值到最低值</li>
</ul>
<h4>自定义字段参数</h4>
<p>根据自定义关键字或值检索文章（或页面）。</p>
<ul>
<li>meta_key=</li>
<li>meta_value=</li>
<li>meta_compare= —— 用以测试meta_value=的操作符，默认值为 &#8216;=&#8217;，其它可能的值包括&#8217;!=&#8217;、 &#8216;&gt;&#8217;、&#8217;&gt;=&#8217;、 &#8216;&lt;&#8216;或 &#8216;&lt;=&#8217; 。</li>
</ul>
<p>返回关键字为 &#8216;color&#8217; 且值为&#8217;blue&#8217;的文章：</p>
<pre>query_posts('meta_key=color&amp;meta_value=blue');</pre>
<p>返回自定义字段关键字为&#8217;color&#8217;的文章，无论自定义字段值为何：</p>
<pre>query_posts('meta_key=color');</pre>
<p>返回自定义字段值为&#8217;color&#8217;的文章，无论关键字为何：</p>
<pre>query_posts('meta_value=color');</pre>
<p>返回自定义字段值为&#8217;green&#8217;的页面，无论自定义字段关键字为何：</p>
<pre>query_posts('post_type=page&amp;meta_value=green');</pre>
<p>返回自定义关键字为&#8217;color&#8217;、自定义字段值不为&#8217;blue&#8217;的文章和页面：</p>
<pre>query_posts('post_type=any&amp;meta_key=color&amp;meta_compare=!=&amp;meta_value=blue');</pre>
<p>返回自定义字段关键字为&#8217;miles&#8217;、自定义字段值小于等于22的文章。注意，字段值99会被看做大于字段值100，因为数据是以字符串形式而不是数字形式存储的。</p>
<pre>query_posts('meta_key=miles&amp;meta_compare=&lt;=&amp;meta_value=22');</pre>
<h4>联合参数</h4>
<p>你可能已经从上面有些例子中看出来了，可以用&amp;符号连接不同参数，如：</p>
<pre>uery_posts('cat=3&amp;year=2004');</pre>
<p>显示主页上、当前月份发表的、隶属于分类13下的文章：</p>
<p>if (is_home()) {<br />
query_posts($query_string . &#8216;&amp;cat=13&amp;monthnum=&#8217; . date(&#8216;n&#8217;,current_time(&#8216;timestamp&#8217;)));<br />
}</p>
<p>在WP 2.3中，以下参数联合会返回同时属于分类1和分类3的两篇文章，以文章标题降序排列：</p>
<pre> query_posts(array('category__and'=&gt;array(1,3),'posts_per_page'=&gt;2,'orderby'=&gt;title,'order'=&gt;DESC));</pre>
<p>在WP 2.3和WP 2.5中，以下参数联合本应返回属于分类1且带有“apples”标签的文章：</p>
<pre>query_posts('cat=1&amp;tag=apples');</pre>
<p>但由于一个bug，代码没能显示出正常结果。有一个解决办法：利用+号查找多个标签：</p>
<pre>query_posts('cat=1&amp;tag=apples+apples');</pre>
<p>这就显示出我们希望显示的结果了。</p>
<h3>使用技巧</h3>
<p>设置&gt;阅读中的“博客页面最多显示”参数会影响你的查询结果，要覆盖设置&gt;阅读中的设置，需要在标签中添加&#8217;posts_per_page&#8217; 参数。例如：</p>
<pre>query_posts('category_name=The Category Name&amp;posts_per_page=-1');  //returns ALL from the category</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>WordPress主题分别列出每类下文章</title>
		<link>https://www.3code.cn/wordpress%e4%b8%bb%e9%a2%98%e5%88%86%e5%88%ab%e5%88%97%e5%87%ba%e6%af%8f%e7%b1%bb%e4%b8%8b%e6%96%87%e7%ab%a0/</link>
		
		<dc:creator><![CDATA[寒林]]></dc:creator>
		<pubDate>Fri, 10 Dec 2010 09:42:40 +0000</pubDate>
				<category><![CDATA[WORDPRESS主题技术]]></category>
		<category><![CDATA[wordpress主题]]></category>
		<category><![CDATA[wordpress函数]]></category>
		<guid isPermaLink="false">https://www.3code.cn/?p=2352</guid>

					<description><![CDATA[WordPress得到所有分类比较简单，我们用”wp_list_categories()”函数就可以实现，下面利用“get_categories()”函数，来分别列出每一类别下的文章列表。]]></description>
										<content:encoded><![CDATA[<p>WordPress得到所有分类比较简单，我们用”wp_list_categories()”函数就可以实现，下面利用“get_categories()”函数，来分别列出每一类别下的文章列表。</p>
<p>下面的代码就是得到所有的分类，并显示出每个分类下最新的10篇文章：</p>
<p>&lt;?php<br />
// 得到所有分类列表<br />
$categories = get_categories();</p>
<p>// 循环所有分类<br />
foreach ($categories as $cat) {</p>
<p>// 得到分类ID<br />
$catid = $cat-&gt;cat_ID;</p>
<p>// 得到分类下10篇最新文章<br />
query_posts(&#8220;showposts=10&amp;cat=$catid&#8221;); ?&gt;</p>
<p>&lt;!&#8211; 输出分类标题及链接 &#8211;&gt;<br />
&lt;h4&gt;&lt;a href=&#8221;&lt;?php echo get_category_link($catid);?&gt;&#8221;<br />
title=&#8221;&lt;?php echo strip_tags(category_description($catid)); ?&gt;&#8221;&gt;<br />
&lt;?php single_cat_title(); ?&gt;<br />
&lt;/a&gt;&lt;/h4&gt;</p>
<p>&lt;!&#8211; 输出10篇最新文章的标题及链接 &#8211;&gt;<br />
&lt;ul&gt;<br />
&lt;?php while (have_posts()) : the_post(); ?&gt;<br />
&lt;li&gt;<br />
&lt;a href=&#8221;&lt;?php the_permalink() ?&gt;&#8221; title=&#8221;&lt;?php the_title(); ?&gt;&#8221;&gt;<br />
&lt;?php the_title(); ?&gt;&lt;/a&gt;<br />
&lt;?php the_time(&#8216;m-d&#8217;); ?&gt;<br />
&lt;/li&gt;<br />
&lt;?php endwhile; ?&gt;<br />
&lt;/ul&gt;<br />
&lt;?php } ?&gt;</p>
<p><strong>效果类似如下：</strong></p>
<li><strong>分类一</strong>
<ul>
<li>文章一</li>
<li>文章二</li>
<li>文章三</li>
</ul>
</li>
<li><strong>分类二</strong>
<ul>
<li>文章一</li>
<li>文章二</li>
<li>文章三</li>
</ul>
</li>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>is_home()与is_front_page()使用</title>
		<link>https://www.3code.cn/is_home-is_front_page/</link>
		
		<dc:creator><![CDATA[寒林]]></dc:creator>
		<pubDate>Sun, 29 Aug 2010 05:29:53 +0000</pubDate>
				<category><![CDATA[WORDPRESS主题技术]]></category>
		<category><![CDATA[wordpress函数]]></category>
		<category><![CDATA[wp]]></category>
		<guid isPermaLink="false">https://www.3code.cn/?p=2032</guid>

					<description><![CDATA[有时候我们需要用到is_home()来判断是不是wordpress的首页，从而进行一些相关配置，但是有一点需要注意，当你的首页不是默认的index.php的时候，比如是在后台指定了一个页面。这种情况下is_home也会失效。
]]></description>
										<content:encoded><![CDATA[<p>有时候我们需要用到is_home()来判断是不是wordpress的首页，从而进行一些相关配置，但是有一点需要注意，当你的首页不是默认的index.php的时候，比如是在后台指定了一个页面。这种情况下is_home也会失效。</p>
<p>也就是说这样子的情况下就不能再用is_home来判断了。而是要用is_front_page来进行判断。is_front_page是判断当前页是不是指定的首页。</p>
<p>故小小记录一下，方便自己与朋友查询。</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>get_page_link</title>
		<link>https://www.3code.cn/get_page_link/</link>
		
		<dc:creator><![CDATA[寒林]]></dc:creator>
		<pubDate>Wed, 21 Jul 2010 07:48:46 +0000</pubDate>
				<category><![CDATA[WORDPRESS主题技术]]></category>
		<category><![CDATA[wordpress函数]]></category>
		<category><![CDATA[wp]]></category>
		<guid isPermaLink="false">https://www.3code.cn/?p=1727</guid>

					<description><![CDATA[wordpress常用函数。据页面ID获取页面的链接]]></description>
										<content:encoded><![CDATA[<p><strong>说明：</strong><br />
根据页面ID获取页面的链接</p>
<p><strong>用法：</strong><br />
&lt;a href=&#8221;&lt;?php echo get_page_link($ancestors[$i]);  ?&gt;&#8221;&gt;&lt;?=get_the_title($ancestors[$i])?&gt;&lt;/a&gt;</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
