DIY


19
Feb 12

How to add a class “parent” to all parent menu items

WordPress menu is a great feature. However you may need some customize to get it right your idea. For example, by default WordPress doesn’t add a parent class to parent menu item.

This is a quick code which I figured out when looking at menu code of WordPress (nav-menu-template.pp and class-wp-walker.php). I tested it with my local of WordPress. It can not good performance but at least it worked.

The idea is to add a filter on wp_nav_menu_objects. loop over element and check if it has a sub or not.

<?php
add_filter('wp_nav_menu_objects', function ($items) {
$hasSub = function ($menu_item_id, &$items) {
foreach ($items as $item) {
if ($item->menu_item_parent && $item->menu_item_parent==$menu_item_id) {
return true;
}
}
return false;
};

foreach ($items as &$item) {
if ($hasSub($item->ID, &$items)) {
$item->classes[] = 'menu-parent-item'; // all elements of field "classes" of a menu item get join together and render to class attribute of <li> element in HTML
break;
}
}
return $items;
});


11
Apr 11

SweetNotify, easiest way to add notification message to WordPress site

SweetNotify is a WordPress Notification Message plugin! It lets u define a notification for your wordpress! It supports global message for whole of site or a specified post/page!

I surely bet that many times you want to have some messages appear on your page to notify visitors something new such as: which time your system will be maintained, tell user checkout your lastest product,…! Yeah, SweetNotify enables you to set it up easily! And yes, it can be a great, sweet solution to replace Hello Bar! What u need to do is to buy it, then install it on your site and use it :D

Feature:

  • Set up notification for whole of site!
  • Set up notification for specified post (Just appear when you go to that post)
  • One-time(just appear on the first time see page, auto disappear on next visiting time)
    or always-on(always appear on top of page) or user-hide(appear till when user click hide button) notification
  • Support 3 positions: top, bottom, center& 4 notification types (info, warning, error, success) with 4 colors and icons!
  • Display notification as dialog box, on top or bottom of page, or even in the top or bottom of post!

Note when testing

When u clicked close button to dismiss the message and want to see it again! U
must clear your cookie! If you don’t know how to clear your cookie, just append
?reset-sweet-notify=true to any url of your site then visit it to Sweet Notify clear its cookie for you! For example,
i can visit one of following url to clear Sweet Notify cookie:
http://axcoto.com/blog/?reset-sweet-notify=true
http://axcoto.com/d/codecanyon/blog/?reset-sweet-notify=true
http://axcoto.com/d/codecanyon/blog/article/588?reset-sweet-notify=true

Demo

This post
Only global message for whole site
Global message and notification message of single page
Global message at top& single post message at bottom.
Another demo with error box type and global message! Both of message are at the top.

Support

You can go to here http://support.axcoto.com/ and post your question into correct category! I will reply there to help you! I’m happy to assist
all of my buyers ;) !

Buy it here


12
Feb 11

Why i go with VIM Part1: Key Navigation

I read many code from github, many open source projects,…One thing which i’m always curious is why they use VIM!

For now, i had my answer, it’s keyboard navigation! Using VIM, you can get rid of your mouse! I’m a big fan of keyboard! I hate to using mouse and move my hand so much! Also it has modes which allow you use command to control your editor!

  • Go to next word, previous word, end of line, beginning of line,…hjklwWbBeE$^! If a key does a job, add a number right before it can do some magic! For example, enter 10G will go to line 10! Or enter 10j will go to next 10 line! All of us hate arrow keys, because it makes us move hand to right! Ok, now we use hjkl without any moving ;) ! 5b will go back 5 words
  • To search, just type /word then use # or * to go next, previous result
  • Use { } to go to block of code which sepeaate by line ;) ! I know you love it
  • [[ leads you to the beginning of function! ]] does otherwise
  • Put cursor at $var, then type gd in normal mode, it will lead you to the first occurring! or use gD to find the first position of current global varrible! Quite coll, right
  • Wanna format code, gg=G! So wonderful!!!

So far, all are about navigation! My hand is quite painful as i work in front of computer like 18hours/day! Without VIM, my life sucks! Thank god for bring VIM to me!


8
Feb 11

Achetes, a funny facebook application, my latest item on CodeCanyon

Ok, i sell stuff on CodeCanyon to earn passive income! This week, i released a new item http://codecanyon.net/item/achites-facebook-app-let-u-have-fun-with-friends/157664
You can see a demo here

Basically, it asks users funny questions about thier friends, then post on wall of friend! It use dialog box to avoid any problem with facebook! Facebook think of you are spammer when you keep posting to wall of friend automatically with old rest api!

You can add your own questions!
Users who have answers (thier friends answered about them via app) can unlock, in other way – see result, using coin! To get coin, they must answer question about thier friends, or using real money to buy coin via gWallet! That way, you can earn some money too!

The application use new GRAPH API! If you are looking foward learning Facebook Graph API, this will be a great application for you! Also it is written in Kohana! That way it becomes a facebook platform to you can build your own application based on this platform! For example, you don’t need to worry about config: canvas, application id, secret key, authorize,..Everything is written and packed into library so you can use it

Anyway, but it while it’s so hot http://codecanyon.net/item/achites-facebook-app-let-u-have-fun-with-friends/157664


27
Jan 11

Faceook Connect: FB.UI error: Sorry, something went wrong.

Today i’m working on a facebook application which needs to post to wall of user’s friend!
Here is my application http://apps.facebook.com/axcotobuzz/, and it’s a IFRAME app! So i used FB.UI with method feed or stream.publish to post to wall!

I read document carefully, it seems everything is easy here:

http://developers.facebook.com/docs/reference/javascript/fb.ui/

http://fbdevwiki.com/wiki/FB.ui

http://developers.facebook.com/docs/reference/dialogs/feed

http://developers.facebook.com/docs/reference/dialogs/feed

After go thorought over them, i then wrote my code as below:

<script>
 challenge.setQuestion('<?php echo $friend->id ?>', '<?php echo $question['id'] ?>');
 FB.ui({
 method: 'stream.publish',
 display: 'popup',
 name: 'Axcoto',
 link: 'http://axcoto.com/',
 message: '90',
 to: 100001785219571,
 redirect_uri: '<?php echo $facebook->conf['canvas']['url'];?>quizz/publishPostBack/',
 }, function () {

 });

 </script>

Clear cache, refresh app…and what i got

Sorry, something went wrong.

We’re working on getting this fixed as soon as we can.

I re-read document carefully, nothing is wrong with my code! And someone is encountering it too

http://developers.facebook.com/docs/reference/dialogs/feed

After some effort, realize that its cause is extra parameter “next” in URL which FB.UI generate

Look at my URL:

http://www.facebook.com/dialog/feed?

app_id=188071914544841&
caption=AAA&description=89.&
link=http%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Freference%2Fdialogs%2F&locale=en_US&message=90!&name=Facebook%20Dialogs&next=http%3A%2F%2Fstatic.ak.fbcdn.net%2Fconnect%2Fxd_proxy.php%23cb%3Df35e4913995012%26relation%3Dopener%26frame%3Df65d68044d6ac%26result%3D%2522xxRESULTTOKENxx%2522&picture=http%3A%2F%2Ffbrell.com%2Ff8.jpg&redirect_uri=http://axcoto.homelinux.org/axcotobuzz/quizz&sdk=joey

I then tried to removed it, took it like this:

http://www.facebook.com/dialog/feed?

app_id=188071914544841&
caption=AAA&description=89.&
link=http%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Freference%2Fdialogs%2F&locale=en_US&message=90!&name=Facebook%20Dialogs&picture=http%3A%2F%2Ffbrell.com%2Ff8.jpg&redirect_uri=http://axcoto.homelinux.org/axcotobuzz/quizz&sdk=joey

Manually enter it on address bar, it works!!! Amazing, but it DOES work!

I dunno the reason, but after figuring out it, i set “next” to null like this:


<script>
 challenge.setQuestion('<?php echo $friend->id ?>', '<?php echo $question['id'] ?>');
 FB.ui({
 method: 'stream.publish',
 display: 'popup',
 name: 'Axcoto',
 link: 'http://axcoto.com/',
 message: '90',
 to: 100001785219571,
 redirect_uri: '<?php echo $facebook->conf['canvas']['url'];?>quizz/publishPostBack/',
 next: null
 }, function () {

 });

 </script>

Clear cache, F5! It works like a charm!

Hope this helps you!


2
Dec 10

Moment – Second item on CodeCanyon

Today, my second item on CodeCanyon was approved for sale! I’m really happy! My way is not good when coming USA! Lacking money, food, computer,…I tried my best, i never get sleep in the night! But thing seems getting better now! At least, i can take some breaths now!

I call it “Moment”, because it’s a moment for me, at this time, when i go my very first step on my way lonely! No fiend, no one stay beside me! I miss my Vietnamese friends much!

This item is for Kohana lover, a gallery to let people upload and share their picture! It lets users comment, like picture! And cooler, it’s written in Kohana! I know many people is wanting to learn Kohana! So please use this item ;) ! You get full support from me for it!

Thank you!

http://codecanyon.net/item/moment-gallery-easy-to-let-people-share-picture-/143338


25
Nov 10

What am i working on?

Yes, after my very fist item on CodeCanyon.Com you maybe want to know what i’m working on, any plant?

My answer: I’m working on a new theme to sell on ThemeForest.Com! It will be a minimal, clean, clear, strong, focus on content theme

Basically, it supports:

  • port folio page
  • gallery short code
  • table short code
  • video short code
  • Sidebar:
    • Custom icon for menu
    • About Section
    • Client Section
    • Lastest project
    • Social link
    • Custom head link
  • 3 page layout:
    • Theree colum
    • One colum
    • Two column

I will upload it with in 1week, hope you like it and buy it ;) !


25
Nov 10

My first item on CodeCanyon

After many days thinking of about Envato, finally i decide to start my work on Envato! My first item is Slidy! You can check it out: http://codecanyon.net/item/slidy/139900

What’s Slidy? – top

Slidy is an elegant and simple jquery plugin to make a slider rating bar or anything with a slider bar! Something like star voting, but for now, it’a bar with scale, interval. Its easy to setup and customize

The facts:

1. Easy to set up and use! No special markup, no any extra css! Include JavaScript file then use it ;)
2. It’s 100% skinnable by only one image.
3. It’s a jQuery plugin.

You can buy item on http://codecanyon.net/item/slidy/139900 with only $5, and i will be happy to assit you for any customize!


7
Nov 10

Apply custom background to an other element(not body) in WordPress

WordPress alows use a custom background, when activating this on your theme, wordpress auto insert a stylesheet into head section look like this

<style type="text/css">
body { background-image: url('http://localhost/rico/wp-content/uploads/2010/11/sarah-shahi-31.jpg'); background-repeat: repeat; background-position: top center; background-attachment: scroll; }
</style>

If you want to stick background to a custom element such as a div element which only wraps content (don’t wrap header, footer) you can use add_cstom_background with a call back to our function to re-define stylesheet which inject into section!

<?php
add_custom_background('_axcoto_custom_background_cb');
function _axcoto_custom_background_cb() {
	$background = get_background_image();
	$color = get_background_color();
	if ( ! $background && ! $color )
		return;

	$style = $color ? "background-color: #$color;" : '';

	if ( $background ) {
		$image = " background-image: url('$background');";

		$repeat = get_theme_mod( 'background_repeat', 'repeat' );
		if ( ! in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) )
			$repeat = 'repeat';
		$repeat = " background-repeat: $repeat;";

		$position = get_theme_mod( 'background_position_x', 'left' );
		if ( ! in_array( $position, array( 'center', 'right', 'left' ) ) )
			$position = 'left';
		$position = " background-position: top $position;";

		$attachment = get_theme_mod( 'background_attachment', 'scroll' );
		if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) )
			$attachment = 'scroll';
		$attachment = " background-attachment: $attachment;";

		$style .= $image . $repeat . $position . $attachment;
	}
?>
<style type="text/css">
#element_id { <?php echo trim( $style ); ?> }
</style>
<?php
}

Please not to change code from line 4 to line 29! This is code to get background and all css property! You can name _axcoto_custom_background_cb anything you want! And you can use any css selector instead of #element_id to apply background to your specific element!


6
Nov 10

Facebook application auto sync twitter to facebook with custom hashtag

Today, i released a small tool which auto sync your twitter tweets to faceook! Cool thing is this app alows you to define your own hashtag to syn! Only tweets contain #your-hashtag will be sync! others are not!

You can try app here:

http://apps.facebook.com/axcototweet/

The application require offline_access to update your status to facebook! When giving this extend permission to app, facebook will return a long live session key which app can use to post tweet to facebook as status!

This app is built on Kohana ;) !