網頁

顯示具有 wordpress 標籤的文章。 顯示所有文章
顯示具有 wordpress 標籤的文章。 顯示所有文章

2014年4月30日 星期三

wordpress tags

Description

Retrieve the list of tags for a post.

Usage


<?php wp_get_post_tags( $post_id, $args ) ?>
example:
   $tags = wp_get_post_tags($post_id); //json_encode($tags);   foreach ( $tags as $tag ) $my_tags .= "#".$tag->name." "; echo("<script>console.log(' rb_get_post_format_content ". $my_tags . "');</script>");   $my_tags_html ='<p>'.$my_tags.'</p>';

功能迴聲(或顯示?)WordPress的標籤頭部分


2013年12月4日 星期三

wordpress install

WordPress架站教學  以000webhost免費空間為例,含申請、安裝、設定等完整步驟



Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 57 bytes) in /home/xxxxx/public_html/wordpress/wp-includes/pomo/mo.php on line238

「wp-config.php」進行修改
加入「define(‘WP_MAX_MEMORY_LIMIT’, ’256M’);」



安裝完WordPress之後必做的22件事


1 更改管理員的暱稱,不要使用帳號

2013年12月3日 星期二

WordPress Plugins IPU-Chart

圖表外掛

IPU-Chart

... chart ipu-chart screenshot 11 IPU-Chart Editor ipu-chart screenshot 2 Horizontal bar chart ipu-chart screenshot 3 Pie chart ipu-chart screenshot 4 Donut chart ipu-chart screenshot 5 Line chart ipu-chart ...
  • Version: 0.8
  • Updated: 2013-11-23
  • Downloads: 2,669
  • Average Rating:
    3 stars
    (3)
https://www.ipublia.com/support/docs/



ip4.color.random 改固定 js/ip4.v0.min.js

ip4.color.random = function(count) {
 /*   
    var a = count,
        b = [],
        c;
    a = "number" !== typeof a ? 1 : a;
    for (c = 0; c < a; c += 1)
        b.push("#" + Math.floor(16777215 * Math.random()).toString(16));
    return b.length > 1 ? b : b[0];
*/

    //改為固定色系順序

    var randomArray = [
       '#2080C8','#99FFE3','#C6FF6F','#FFF069','#FF3366','#5CE1F3','#005872'
    ];

    return randomArray;
}

2013年11月27日 星期三

WordPress debug

PHP Warning: Missing argument 2 for wpdb::prepare()


Hello plugin or theme author! You possibly found this post after searching the Internet for the error above: “PHP Warning: Missing argument 2 for wpdb::prepare().”
So, this is a new warning in 3.5. No sites are broken, everything is fine as before. But, this is indeed something you need to look at, because you may be exposing your users to a possible SQL injection vulnerability. Now that’s no fun!

There’s where the problem lies:
1
$wpdb->prepare( "SELECT * FROM table WHERE id = $id" );
See the problem? That query isn’t secure! You may think you are “preparing” this query, but you’re not — you’re passing $id directly into the query, unprepared. And this, right here, is why $wpdb->prepare() now issues a warning if it isn’t called with more than one argument. Because you can’t prepare a query without more than one argument. Here’s a correct example:
1
$wpdb->prepare( "SELECT * FROM table WHERE id = %d", $id );



echo("<script>console.log('function php');</script>");

2013年11月24日 星期日

Wordpress functions.php

How can I redirect users to the front page after log in? 


/* redirect users to front page after login */
function redirect_to_front_page() {
global $redirect_to;
if (!isset($_GET['redirect_to'])) {
$redirect_to = get_option('siteurl');
}
}
add_action('login_form', 'redirect_to_front_page');

Customize WordPress Logout URL



Add filter

Add this line to your theme ‘functions.php‘ file or to your plugin main file.
add_filter('logout_url', 'my_logout_url');

Add function

function my_logout_url( $logout_url, $redirect = null ) {
 return $logout_url . '&amp;redirect_to=' . 'http://my-logout-page';
}

2013年11月21日 星期四

Wordpress and MySQL

UPDATE
 

        $option_tree_value_mysql = 's:5:"title";s:9:"post";s:4:"page";';
        $table_name = 'wp_options';
        $option_id =100;
        $sql = "UPDATE $table_name SET option_value='$option_tree_value_mysql'  WHERE option_id=$option_id";
  $ereminders = $wpdb->query($wpdb->prepare($sql));


 

    /* 參數測試 */
    $wp_user_id =2;
    $wp_post_id =1;

 
    $user_blogs_array =  get_blogs_of_user( $wp_user_id ); //Notice: 開啓debug模式有 wordpress 3.1前棄用的訊息

 foreach ($user_blogs_array AS $user_blog) {

      $wp_blog_id = $user_blog->userblog_id;
     
 }
     $table_name = 'wp_'.$wp_blog_id.'_postmeta';//'wp_2_options';
     $sql = "UPDATE $table_name SET meta_value=%d  WHERE meta_key='條件' AND post_id='1'";
  $ereminders = $wpdb->query($wpdb->prepare($sql,3)); 


2013年11月14日 星期四

WordPress custom




Simplifying ‘My Sites’ toolbar menu in WordPress multisite

  

//remove wordpress logo/pages from admin bar
function annointed_admin_bar_remove() {
        global $wp_admin_bar;


 /* Remove their stuff */

   $wp_admin_bar->remove_node('wp-logo');
    // $wp_admin_bar->remove_node('about');
    // $wp_admin_bar->remove_node('wporg');
    // $wp_admin_bar->remove_node('documentation');
    // $wp_admin_bar->remove_node('support-forums');
    // $wp_admin_bar->remove_node('feedback');
    // $wp_admin_bar->remove_node('view-site');

        $wp_admin_bar->remove_node('my-sites');
       // $wp_admin_bar->remove_node('blog-2-d');

         $current_user = wp_get_current_user();
       
        $updates_node = $wp_admin_bar->get_node() ;
         $wp_admin_bar->add_menu( array(
  'id'    => 'jpl-my-sites',
  'title' =>  'My Sites',
  'href'  =>   get_site_url( $current_user->ID ),
  'meta'  => array(
   'title' => __('My Sites'),   
  ),
    ));
}

add_action('wp_before_admin_bar_render', 'annointed_admin_bar_remove', 0);


WordPress開發網站外掛筆記

WP客製化 #4: 客製 WordPress 後台登入 LOGO、連結、版權訊息、後台首頁訊息資訊 (非外掛)


 remove wordpress logo/pages from admin bar





6 WordPress Login Modifications

2013年10月20日 星期日

wordpress post

彻底解决wordpress文章ID不连续显示的问题


/** 禁用修改版。 */
define(‘AUTOSAVE_INTERVAL’, 120000000 ); // 设置自动保存间隔,单位是秒,默认60

define(‘WP_POST_REVISIONS’, false ); // 禁用文章修订功能





透過name取得page的 wp_posts #id

Get a post by its slug

Allows you to get a post ID by post slug.
<?php
$the_slug = 'my-slug';
$args=array(
 'name' => $the_slug,
 'post_type' => 'page',
 'post_status' => 'publish',
 'posts_per_page' => 1
);
$my_posts = get_posts( $args );
if( $my_posts ) {
 echo 'ID on the first post found ' . $my_posts[0]->ID;
}
?>

WP_Query、query_posts() 和 get_posts()应该在什么时候使用

WordPress输出文章最常见的函数是query_posts(),但query_posts()不是唯一的方式,而且乱用query_posts()不是一个好习惯。get_posts()或者WP_Query也可以达到相同的作用。看了一篇文章,描述了这三者的区别。

query_posts()

query_posts()主要用来输出主循环,并且会创建很多全局变量。因此不适合到处使用,最佳使用场所就是输出主循环,别的地方能不用就不要用。如果一定要用,记得在输出结果以后使用wp_reset_query()函数重置查询结果,防止意外修改主循环和全局变量产生一堆莫名其妙的错误。

get_posts()

get_posts()的机制与query_posts()类似,参数也相同,是一种简单的获取文章的方法,get_posts()不会产生全局变量,不影响主循环,非常安全。如果要在主循环之外输出最新文章、特色文章等,不妨考虑用这个。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//get_posts参数
<?php
$args = array(
 'numberposts'  => 5,
 'offset'    => 0,
 'category'  => ,
 'orderby'   => 'post_date',
 'order'     => 'DESC',
 'include'   => ,
 'exclude'   => ,
 'meta_key'  => ,
 'meta_value'   => ,
 'post_type'    => 'post',
 'post_mime_type'  => ,
 'post_parent'  => ,
 'post_status'  => 'publish' ); ?>

WP_Query


WP_Query是前两个函数的基础,使用起来更复杂,但限制也少。适合创建功能比较特殊的自定义循环,也完全可以取代上面两个函数。

Example

Before calling wp_update_post() it is necessary to create an array to pass the necessary elements. Unlikewp_insert_post(), it is only necessary to pass the ID of the post to be updated and the elements to be updated. The names of the elements should match those in the database.

// Update post 37
  $my_post = array(
      'ID'           => 37,
      'post_content' => 'This is the updated content.'
  );

// Update the post into the database
  wp_update_post( $my_post );