- foreach((get_the_category()) as $category) {
- if($category->cat_ID == "1"){
- echo $category->cat_name;
- }elseif($category->category_parent=="1"){
- echo $category->cat_name . '教程 ';
- }
- else{
- echo $category->cat_name . '面试题 ';
- }
- }
Category Archives: wordpress
获取热评文章
- $postslist = get_posts('numberposts=10&order=DESC&orderby=comment_count');
- foreach( $postslist as $post ) : ?>
- <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>(<?php echo $post->comment_count; ?>)
- </li>
- <?php endforeach; ?>
获取随机文章
- <?php
- $rand_posts = get_posts('numberposts=10&orderby=rand');
- foreach( $rand_posts as $post ) :
- ?>
- <!--下面是你想自定义的Loop-->
- <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
- <?php endforeach; ?>
获取最新文章
方法一
- <?php $posts = get_posts("numberposts=20&order=DESC&orderby=id" ); ?>
- <?php if( $posts ) : ?>
- <ul><?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
- <li>
- <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">
- <?php
- if (mb_strlen($post->post_title) > 14) {
- echo mb_substr($post->post_title, 0, 14,'utf-8') . '...';
- } else
- {echo the_title();}
- ?>
- </a>
- </li>
- <?php endforeach; ?>
- </ul>
- <?php endif; ?>
方法二
- <?php get_archives('postbypost', 10); ?> (显示10篇最新更新文章)
方法三
显示你博客中最新的20篇文章,其中format=custom这里主要用来自定义这份文章列表的显示样式
- <?php wp_get_archives('type=postbypost&limit=20&format=custom'); ?>
解决FCKeditor表单校验时第一次为空(需要提交两次)的问题
校验脚本:
- <script language="javascript">
- function check(){
- if(FCKeditorAPI.GetInstance("content").GetXHTML()==''){
- alert("文章内容不允许为空");
- return false;
- }
- }
- </script>
Call to undefined function xmlrpc_encode_request()
错误信息:Call to undefined function xmlrpc_encode_request()
解决办法:打开php.ini文件,去掉extension=php_xmlrpc.dll前面的分号
解决wordpress 3.1升级后首页打不开的问题
wordpress更新到3.1出现首页开不开重定向循环的情况:google提示网页生成了过多的重定向。清除此网站的 Cookie 或允许第三方 Cookie 可能会解决该问题。如果不能解决,则可能是服务器配置的问题,而不是您的计算机有问题。
解决办法如下:
直接把这句代码加到主题的functions.php模板文件中
- remove_filter('template_redirect', 'redirect_canonical');
关于wordpress 3.1升级至首页重定向循环原因参考:
wordpress 3.1引入Canonical URL Redirection技术
wordpress升级备忘录
下面是对wordpress做的修改记录,升级的时候,不能覆盖下列文件
1. classes.php
2. wp-includes/category-template.php
- /**
- 根据id获取其顶级分类的id
- **/
- function get_category_top_id($id) {
- $parent = &get_category( $id );
- if ( is_wp_error( $parent ) )
- return $id;
- if ( $parent->parent && ( $parent->parent != $parent->term_id )) {
- $id = get_category_top_id( $parent->parent);
- }
- return $id;
- }
- /*
- 根据分类的id,得到分类名称
- */
- function get_category_title($prefix = '', $cat,$display=True) {
- if ( !empty($cat) && !(strtoupper($cat) == 'ALL') ) {
- $my_cat_name = apply_filters('single_cat_title', get_the_category_by_ID($cat));
- if ( !empty($my_cat_name) ) {
- if ( $display )
- echo $prefix.strip_tags($my_cat_name);
- else
- return strip_tags($my_cat_name);
- }
- } else if ( is_tag() ) {
- return single_tag_title($prefix, $display);
- }
- }
wordpress调用分类下的文章
- <?php $posts = get_posts("category=1&numberposts=10"); ?>
- <?php if( $posts ) : ?>
- <ul><?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
- <li>
- <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
- </li>
- <?php endforeach; ?>
- </ul>
- <?php endif; ?>
wordpress在IIS下无rewrite利用cos-html-cache实现静态页面
cos-html-cache是个很不错的,可以生成静态html文件的插件,可是如作者所说“cos-html-cache插件是需要urlrewrite支持的,不幸的是这个条件已经将国内的70%的虚拟主机挡在门外了”,我也是因为urlrewrite都原因,一直徘徊在实现html静态页面都大门之外,看着网站的速度越来越慢,可是又改变不了这种现状,已经让我失眠几个晚上。
前段时间想自己写个程序,不用urlrewrite来生成html。今晚想正式开始做,于是就想到借鉴一下cos-html-cache,无意中看到了“图解cos-html-cache原理”这篇文章,就仔细都读了一下,果然受到启发,由此我又想到了以前看到的一篇文章“IIS下不用Rewrite实现wordpress伪静态”,说实话,第一次看到这篇文章都时候挺不屑的,因为我现在不要华丽的URL,不要什么所谓的SEO,我要的是实实在在的访问速度,没有了性能,我没心情搞那些花哨的东西。
首先cos-html-cache的原理就是,当访问者请求一个网址的时候,如/html/2009/110.html,服务器首先会去相关的文件夹(/html/2009/)下寻找文件(110.html)是否存在,如果存在则直接将该文件发送给浏览者,否则发送一个404文件未找到的错误给浏览者,所以我们只要设置好IIS的404错误页面,当访问出现404错误的时候,自动访问首页(index.php)即可,剩下都任务交给cos-html-cache来处理,它会自动为你生成html文件。
第一步,如“IIS下不用Rewrite实现wordpress伪静态”所说,在网站根目录新建一个404.php文件,内容如下:
<?php
$qs = $_SERVER['QUERY_STRING'];
$_SERVER['REQUEST_URI'] = substr($qs, strpos($qs, ‘:80′)+3);
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];
include(‘index.php’);
?>
第二步,在IIS的网站属性-自定义错误里面,将404错误的地址改成URL形式的,地址为/404.php
第三步,将永久链接改成自定义的一个访问路径,如/html/%post_id%.html
第四步,安装上cos-html-cache,享受html带给你的速度吧(如果没有正确生成html,请参考cos-html-cache的说明文件)
希望所有用IIS作php服务器并且无法用urlrewrite的武林同道,wordpress生成html成功!