2015年12月11日 星期五

[wordpress]利用程式自動新增文章並預設特色圖片

本段程式是自己改寫於新增portfolio文章與新增post文章有點不同

function auto_post(){
$postData = array(
'post_title'    => 'My portfolio post',
'post_content'  => '',
'post_type'      => 'dt_portfolio', // Default 'post',預設值是post
'post_status'   => 'publish',
'post_author'   => 1
);
  // 新增文章並取得post_id
$post_id = wp_insert_post( $postData );
             
  $getImageFile =  ABSPATH . 'wp-content/uploads/2015/11/4A7C3296.jpg';// 圖片來源
$wp_filetype = wp_check_filetype( $getImageFile, null );

$attachment_data = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name( $getImageFile ),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment_data, $getImageFile, $post_id );
  require_once( ABSPATH . 'wp-admin/includes/image.php' );
  $attach_data = wp_generate_attachment_metadata( $attach_id, $getImageFile );
  wp_update_attachment_metadata( $attach_id, $attach_data );
  // 設定特色圖片縮圖
  set_post_thumbnail( $post_id, $attach_id );
   // 設定portfolio分類(註)
wp_set_post_terms($post_id, 22, 'dt_portfolio_category');
}



註:假如是文章的話不需在此設定分類,$postData那邊加入以下程式'post_category' => array( $Category ),即可,因為筆者要新增的是portfolio分類所以無法使用該方法,故用wp_set_post_terms()來修改該筆post分類。

2015年12月8日 星期二

2015年12月1日 星期二

[wordpress]woocommerce後台購買日期變成"年/月/日"解決方法

woocommerce後台購買日期變成"年/月/日"是因為語系語翻譯錯誤所造成,可以用poedit去編輯語系檔案,找到"年/月/日"把它改成"y/m/d"再儲存就可以。
檔案路徑:\htdocs\wp-content\languages\plugins\woocommerce-admin-zh_TW.po
註:這是woocommerce官方釋出的翻譯檔就已經出錯,所以此方法在官方未更新翻譯檔的情況下只能治標不能治本。翻譯覆蓋後請記得再去修改。

2015年11月12日 星期四

[javascript]取得螢幕&瀏覽器寬度高度

//取得螢幕寬度
function getScreenWidth() {
return screen.width;
}
//取得螢幕高度
function getScreenHeight() {
return screen.height;
}
//取得瀏覽器視窗寬度
function getBrowserWidth(){
return jQuery(window).width();
}
//取得瀏覽器視窗高度
function getBrowserHeight() {
return jQuery(window).height();
}

2015年10月13日 星期二

[wordpress]在子主題新增jQuery plugin

參考官方建議使用wp_enqueue_script()用來載入 javascript 檔,wp_enqueue_style()用來載入css檔,使用方式如下
wp_enqueue_style( $handle, $src, $deps, $ver, $media );
wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );


wp_enqueue_script() 使用說明:
$handle:用於區別 script 名稱(string);
$src:javascript 檔案位置(string);
$deps:相關性,指此 javascript 必須在此 javascript 之前載入(array,非必需的);
$ver:幫 javascript 加註版本,留空白則使用當前 wordpress 版本號碼(string,非必需);
$in_footer:是否放置到網頁HTML底部載入(boolean,非必需)。

wp_enqueue_style() 使用說明:
$handle:用於區別 CSS 的名稱(string);
$src:CSS 檔案位置(string);
$deps:相關性,指此 CSS 必須在此 CSS 之前載入(array,非必需);
$ver:幫 CSS 加註版本,留空白則使用當前 wordpress 版本號碼(string,非必需);
$media:用於 CSS 的 media 參數值(string,非必需)。

使用範例:
function add_pluginname_scripts() {
    wp_enqueue_style( 'style', get_stylesheet_uri() );
    wp_enqueue_script( 'script', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'add_pluginname_scripts' );

注意事項:
1.請將jQuery plugin放置子主題的資料夾內
2.必須寫在function.php這隻檔案。
3.若是在子主題新增的話,$src的部分請改寫成get_stylesheet_directory_uri()←用來取得子主題的url

2015年9月29日 星期二

[CSS]input 標籤 type number

HTML5 input type number 預設會有上下按鈕加減數字

要關掉這項功能可以下css style關閉

input[type='number'] {
    -moz-appearance:textfield;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

2015年9月14日 星期一

[nas]Synology NAS修改檔案上傳上限

1.先下載putty終端機連線工具
2.連線帳號必須是root,否則無法修改檔案
   密碼為當初設定的密碼
3.登入後修改php.ini檔
   DSM 5.0 之前, php.ini 在 /usr/syno/etc
   DSM 5.0 之後, php.ini 在 /etc/php
4.輸入vi 路徑/php.ini後進入文字編輯模式(按I)
5.修改以下數據
max_execution_time = 600
max_input_time = 600
post_max_size = 210M
upload_max_filesize = 200M
6.修改完後按下esc 再輸入 :wq儲存後離開
7.重新啟動server
   網頁應用程式->啟動web station 勾選取消->套用->再次勾選->套用
   套件中心->phpMyAdmin->啟用

[Laravel]環境架設,使用docker + laradock

1.選擇使用docker + laradock在windows10的環境使用 先至 docker官方網站 下載 docker for windows   2.依照執行程式下載安裝 這邊我的電腦有遇到一些問題順便記錄下來, 在下載啟動docker時發生錯誤   Hardw...