Archive for the ‘php’ Category

排序列出 page entries

Tuesday, June 28th, 2005

我發現 wordpress 在 page 管理頁面設定的 order 根本是設心酸的
不管怎麼設,輸出時還是沒有排序,所以只好動手改一下了

修改 wp-include/template-functions-post.php 這個檔案
我的 theme 是呼叫 wp_list_pages(),看了一下發現他是依照 sql 裡的儲存順序來建 page_tree,所以完全沒考慮到 menu_order。

  // Query pages.
  $pages = & get_pages($args);
  if ( $pages ) :

+ // letoh: sort by menu_order
+ function cmp($a, $b)
+ {
+   if ($a->menu_order == $b->menu_order) {
+     return strcmp($a->post_title, $b->post_title);
+   }
+   return ($a->menu_order < $b->menu_order)?-1:1;
+ }
+ usort( $pages, ‘cmp’ );

  if ( $r[’title_li’] )
    $output .= ‘<li class=”pagenav”>’ . $r[’title_li’] . ‘<ul>’;

我用的解法很簡單,在建 tree 之前,把整個 page 陣列根據 menu_order 排一下就可以了,這樣再建 tree 時會從 menu_order 小的開始考慮,一個一個加進去,這樣就不需要對陣列做插入和搬移的動作了。如果 order 相等就根據 title 來排序,而且這樣排序後就算有 child 也不會有影響 (應該吧…)

PHP Classes

Tuesday, May 3rd, 2005

PHP Classes

      http://www.phpclasses.org/

上面有不少現成的程式碼可以使用

[log] 修改 sem-fancy-excerpt.php

Monday, May 2nd, 2005

原本的 fancy excerpt 根本不能用,中文也有問題
只好自己來了

加上 flickr 的處理,其他的直接取前四行XD

+ $more = ‘[<a href=”‘.get_permalink().’”>more…</a>]<br />’;

if ( $excerpt == ” )
{
      $excerpt = $post->post_content;
      $excerpt = apply_filters( ‘the_content’, $excerpt );
-    $excerpt = strip_tags( $excerpt );
-    $excerpt = preg_replace( “/^\W*(\w+(\W+\w+){”.($excerpt_length-1).”}((?!(!|\?|\.|\n|\r)).)*(!|\?|\.|\n|\r))(\w|\W)+/”, “$1 [more…]”, $excerpt );

+    if (false !== strpos($excerpt, ‘<div class=”flickr-frame”>’) ) {
+          preg_match(’/^.*<div class=”flickr-frame”>(.*\n)*?(.*?)<\/div>/m’,
+                $excerpt, $match);
+          $excerpt = $match[0].’<br />’. $more;
+    } else {
+          preg_match( ‘/(.*\n){4}/m’, $excerpt, $match );
+          if( strlen($excerpt) - strlen($match[0]) > 10 ) {
+                $excerpt = $match[0].’  ’.$more;
+          }
+    }

+ else {
+    $excerpt = $excerpt.’  ’.$more;
}

[pkg] jpGraph

Monday, May 2nd, 2005

JpGraph

      http://www.aditus.nu/jpgraph/

JpGraph is a fully OO (Object-Oriented) Graph creating class library for PHP.

如何讓 JpGraph 顯示中文

      http://blog.yam.com/jaceju/archives/98190.html

[doc] Writing Secure PHP

Saturday, April 30th, 2005

Writing Secure PHP

http://forevergeek.com/programming/writing_secure_php.php
http://www.ilovejackdaniels.com/security/writing-secure-php/