wordpress ---- 相册插件[NextGEN Gallery] 404 错误解决办法


最近wordpress网站出现404错误, URL类似于:
http://www.xxxxxx.com/gallery/10-really-expensive-christmas-gifts/gallery/image/louis-vuitton-condom
http://www.xxxxxx.com/gallery/awesome-gifts-a-man-should-ask-for/gallery/image/louis-vuitton-condom
http://www.xxxxxx.com/gallery/12-must-play-christmas-songs/gallery/image/louis-vuitton-condom
......

看这地址就知道插件开启了Activate permalinks,


遂用下面地址访问
http://www.xxxxxx.com/gallery/10-really-expensive-christmas-gifts/?pid=122
发现能正常访问,初步判断应该是RewriteRules出问题了;

最后查看[NextGEN Gallery]插件源码,一步步排查,发现这个插件不支持此类型的地址
http://www.xxxxxx.com/gallery/10-really-expensive-christmas-gifts/gallery/image/louis-vuitton-condom
仅仅支持此类型的
http://www.xxxxxx.com/10-really-expensive-christmas-gifts/gallery/image/louis-vuitton-condom

打印出RewriteRules就很明白了:
代码如下
  1. [([^/]+)/gallery/page-([0-9]
    ......

wordpress---置顶(sticky)功能排序(order by)


wordpress中有一个很好用的功能--置顶, 现在来研究下使用方法:设置:在列表页点快速编辑(Quick Edit), 然后把置顶勾上,如图


使用:
  1. ......
  2. $sticky = get_option('sticky_posts');
  3. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  4. query_posts
    ......

在wordpress二次开发中实时清空W3 Total Cache缓存


在wordpress二次开发中,假如用到了W3 Total Cache插件,那么在程序中也许需要清空一下缓存, 研究了下W3 Total Cache的源码,发现可以用以下方法实现实时清空W3 Total Cache的缓存,而不用专门跑到它的设置页面清空
代码如下
  1. update_option('widget_unit2_settings',serialize($arr));
  2. if(class_exists('W3_Plugin_TotalCache')){
  3.      //flush cache
  4.     
    ......

在get_posts中使用多个orderby


wordpress中get_posts的用法,官方描述如下:
<?php $args = array(
    'numberposts'     => 5,
    'offset'          => 0,
    'category'        => ,
    'orderby'         => 'post_date',
    'order'           => 'DESC',
    'include'         => ,
    'exclude'         => ,
    'meta_key'        => ,
    'meta_value' &nbs
......

在query_posts中使用LIKE


查看了wordpress文档,发现query_posts不支持like, 解决办法如下:

代码如下
  1. private function __construct()
  2. {
  3.   add_filter('posts_where',array(&$this,'customerWhere'));
  4. }

  5. ......

wordpress 定时任务实例


wordpress定时任务代码:
代码如下
  1. //注册自定义action
  2. function link_titles_to_pages_task()
  3. {
  4.     do_action("link_titles_to_pages_task");
  5. }
  6.  

  7. ......

替换SQL_CALC_FOUND_ROWS和SELECT_FOUND_ROWS()


第一种方法:修改核心代码query.php
wp-includes/query.php

line 2591~2597

代码如下
  1.     if ( !$q['no_found_rows'] && !empty($limits) )
  2.                 //$found_rows = 'SQL_CALC_FOUND_ROWS';      
  3.  
  4.                 $found_rows = ' '
    ......

wordpress 中add_action和add_filter的区别


 The difference is semantic. You can use add_filter() for an action, and you can use add_action() for a filter. The difference is there because actions and filters have a different code “mentality.” Filters are just that, filters through which information is passed, and then used. For example… the contents of this entry are passed through several filters. They turn my line breaks into HTML paragraphs, and correct HTML mistakes. Most importantly, when all filters have been run, something is done with that information. With actions, information may be passed between functions that use the action hook, but nothing is done with the information after all the filters have run. An example would be when I posted this entry publish_post was fired, and passed along the ID of this post. Plugins could use that ID to do things related to this entry, and pass on the ID for other plugins, but after all the plugins have run, the information passed along (the ID) is thrown away. Actions also have the possibility of not passing on any information (“No Parameters” hooks). These are hooks that are merely placeholders… like a template header or an admin footer. These are the only hooks whose functions should not return any information. Important note: actions are not all “No Parameters” hooks! It is still important to return any information you may get when using an action hook… even though WordPress won’t be using it, other plugins might!

--------------------------------------------------------------------
所不同的是语义。你可以使用一个动作add_filter(),
......

    Search On Site