Making YouTube Thumbnail as Post Thumbnail in Wordpress


Creating video thumbnail can be tricky on WordPress. You will need to add new meta on your post so that the post writer can insert the video ID and update the whole post. This time the key of the post meta that I used is video_id. Have a look on the code! 😀

function store_vid_info($post_id){
    if(($_POST['post_status'] == 'publish') && (in_category('video', $post_id))) {
        $vid_id = get_post_meta($post_id, 'video_id'); /* needed to take meta data. The return will be in array */
        $url = "https://gdata.youtube.com/feeds/api/videos/" . $vid_id[0] . "?v=2&alt=jsonc";

        $content = json_decode(file_get_contents($url)); /* If you use curl, then the header will be overrode and result in error. */

        $post = array(
            'ID' => $post_id,
            'post_content' => "" /* This line will insert the video in iframe to the post content */
        );

        /**
         * This will update the post meta (if exist in case of editing post) and will add it.
         * You can change the code to really insert the YouTube thumbnail into your WP thumbnail.
         * I add  the image to a new meta because I'm afraid the theme did not support post thumbnail.
         * If it is, then feel free to change to code.
         */
        if (!update_post_meta($post_id, '_video_thumb', $content->data->thumbnail->hqDefault))
            add_post_meta($post_id, '_video_thumb', $content->data->thumbnail->hqDefault);

        wp_update_post($post);
    }
}

add_action('publish_post','store_vid_info'); /* This will hook the function that we have just made to WordPress publish */

Feel free to give comments and feedback 🙂

File Uploading for CKEditor using CodeIgniter


I know, I know that I haven’t uploaded the source code of my simple project, Blog Manager, yet to github. I have already created the repository, though. This is just a notification update on Blog Manager.

As my boss really planned to make it a wordpress like text editor when adding a post, so I work on CKEditor, a great editor I must say, but quite tiring to create the file browser (it’s just me I think). For now, I have also added the Blog Manager category on this blog, Various Talks.

AS for your information, to create simple upload dialog on CKEditor, you can use the code chunk below for PHP.

PS. I was inspired by this post. So I lazily changed it for CodeIgniter. Yeah because I’d rather change than rethink about the algorithm and read a long example. LOL

public function addphoto($blogID){
	$this->load->model('BlogModel'); // the model that communicate with blog

	$config['upload_path'] = './uploads/';
	$config['allowed_types'] = 'gif|jpg|jpeg|png';
	$config['overwrite'] = FALSE;
	$this->load->library('upload');


	$funcNum = $this->input->get('CKEditorFuncNum'); //$_GET['CKEditorFuncNum']
	$this->upload->initialize($config);
		
	if (!$this->upload->do_upload('upload')){ // upload the file, 'upload' is the name of the field from CKEditor
		 // failed upload
		$message = "Upload failed on blog manager server.";
		$url = '';
	
	}else{ // success copy to wp server
		$upload_result = base_url() . 'uploads/'. $this->upload->data()['file_name'];
		$upload_name = $this->upload->data()['file_name'];

		// after finished uploading, it will receive a URL
		$url = $this->BlogModel->UploadImage($blogID, $upload_result, $upload_name); 

		$message = 'Upload success!';
	}
	echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction($funcNum, '$url', '$message');</script>";
}

Feel free to notify me if you’re interested in this.

Be free to visit it in here!

Blog Manager


So, I was working on this PHP project as I have told you earlier in my post earlier.

It was called as Blog Manager. It is not really complete. I planned to put it in my git repository. I also created the wordpress plugin so that my app can operate well with WordPress.

After I reach to put both Blog Manager web app and Blog Manager WordPress plugin in my git repo, I will continue to add WP tags in the Blog Manager, and extend it to other PHP CMS like Joomla.

If you are interested, come to the git repository. 🙂

Be free to visit it in here!

ngajar wp


Apa sih isi post ini? Dikit sih, liat aja deh.

Tadinya aku mau post pas ngajar. Lalu aku liat paribanku (seperti anak dari saudara laki laki ibu). Dia punya project mau buat web pakai wordpress. Nah, dari situlah aku mulai mengajarkan dia cara pressing. Wkwkwk

Lucu juga kalau tahu aku yang orang awam ini ngajar hal begituan layaknya yang tertulis di head first wordpress. Tapi yah begitulah diriku. Aku ga tau, dan aku cari tau.

Wp-ing itu sebenernya mudah. Yang susah itu mengontrol diri kita untuk menampilkan apa yang penting aja. Misalnya kalau kita lihat dalam diri kita, kita mau banyak hal dalam blog kita. Apalagi kalau misalnya kita punya personal page sendiri yang udah di host di satu name. Nah pastinya kita pengen banyak hal untuk bisa dilihat orang orang di sana kan.

Untuk kita bisa buat itu kan jelasnya banyak sekali plug-in dan widgets bahkan custom plug-in yang harus kita buat biar sesuai dengan selera. Nah, karena itulah kita harus mengontrol diri supaya yang kita masukkan di situ, hal yang berguna, bukan berarti.

Misalnya pertimbangan dalam membangun blog yang super indah dengan banyak perhiasan. Nah, kita pilih mana, gambar yang terload pada tiap page, atau satu page yang punya banyak function dan meload semua gambar sekaligus? Aku sih milih semi. 😀 karena kan ga semua total. Enakan jadi banci kalo program. Hahahahahahah. Just my opinion.

Itu hanya masalah pikiran dan design. Well designed juga ringan. Itu yang menurut aku enak.

Saranku ada beberapa

    taruhlah semua plug-in yang berguna, bukan yang memukau. Pilih yang terbaik dan paling cepat terload.
    pilih gambar yang indah dan ringankan kapasitasnya biar cepet di download.
    kalau bisa buat theme sendiri pakai tool lalu edit codenya biar menghilangkan unsur yang ga perlu.

That’s all folks!

Posted with WordPress for BlackBerry.