Category: WordPress 教學

[QA]SMTP Error: Could not authenticate when using WP SMTP Gmail

Gmail does not allow low security applications to access now by default

https://support.google.com/accounts/answer/6010255

Tags : ,

[WordPress] file and directory permission setting

never use 777  666, it can be hacked to alter or write files

  • Root directory                     0755
  • wp-admin                            0755
  • wp-content                          0755
  • wp-includes                        0755
  • .htaccess                            0640
  • readme.html                      0400
  • wp-config.php                   0644
  • wp-admin/index.php        0644
  • wp-admin/.htaccess         0640
find /path/to/wordpress/dir -type d -print0 | xargs -0 chmod 755
find /path/to/wordpress/dir -type f -print0 | xargs -0 chmod 644
find /path/to/wordpress/dir -name ".htaccess" -print0 | xargs -0 chmod 640
Tags :

[QA] WordPress permalinks 404 Not Found, but .htaccess is ready

be sure to modify /etc/apache2/sites/xxxxxxxx.conf

AllowOverride None -> AllowOverride ALL

restart apache server after file saved

Tags :

WordPress 使用 qTranslate 常見問題

Q1. 使用 get_permalink 所產生網址無法對應正確語言

在 functions.php 內加入:
 
add_filter('post_type_link', 'qtrans_convertURL');

 

Q2. 顯示切換語系功能

<?php echo qtrans_generateLanguageSelectCode('text'); ?>

Q3.

Tags : ,

[教學] Nextgen Gallery 支援中文目錄以及檔案 (unicode, utf-8 folder and filename support)

1. 支援中文目錄

修改 functions.php 內的 create_gallery

function create_gallery($title, $defaultpath, $output = true) {
 
   global $user_ID;
 
   // get the current user ID
   get_currentuserinfo();
 
   //cleanup pathname
   //$name = sanitize_file_name( sanitize_title($title)  );
   //$name = apply_filters('ngg_gallery_name', $name);
   $nggRoot = WINABSPATH . $defaultpath;
   // call wp_unique_filename instead
   $name = wp_unique_filename( $nggRoot, $title, null );
   $txt = '';
 
   ...
}

2. 支援中文檔案

修改 functions.php 內的 scan_dir

function scandir( $dirname = '.' ) { 
   $ext = apply_filters('ngg_allowed_file_types', array('jpeg', 'jpg', 'png', 'gif') );
 
   $files = array(); 
   if( $handle = opendir( $dirname ) ) { 
      while( false !== ( $file = readdir( $handle ) ) ) {
         $info = pathinfo( $file );
         // just look for images with the correct extension
            if ( isset($info['extension']) )
               if ( in_array( strtolower($info['extension']), $ext) ) {
                  // no need encode anymore
                  //$files[] = utf8_encode( $file );
                  $files[] = $file;
               }
      }		
      closedir( $handle ); 
   } 
   sort( $files );
   return ( $files ); 
  }

修改 core.php 內的 fileinfo

function fileinfo( $name ) {
   ...
 
   $filepart['filename'] = urldecode( sanitize_title_with_dashes( $filepart['filename'] ) );
 
   ...
}
Tags : ,

[教學] WordPress page / post 使用自訂 template

1. 加入以下程式碼至 functions.php

function my_post_template($template) {
   if ( !is_single() ) return $template;
   global $wp_query;
   $c_template = get_post_meta( $wp_query->post->ID, '_wp_page_template', true );
   return empty( $c_template ) ? $template : $c_template;
}
 
add_filter( 'template_include', 'my_post_template' );
 
function register_posts_templates() {
   add_post_type_support( 'post', 'page-attributes' );
}
 
add_action( 'init', 'register_posts_templates' );

2. 新增 template-MY_TEMPLATE_NAME.php 至 theme 目錄下, 並加入以下註解至檔頭

<?php
/*
Template Name: MY_TEMPLATE_NAME
*/
...
?>
Tags :