You remember the post How to get a page/post content, don’t you? Then, we may get the page/post content by:

function getPageBySlug( $slug ) 
{
  $objectPost = get_page_by_path($slug);
  return apply_filters("the_content",$objectPost->post_content);
}
Read More

We have to use a little trick! In other words, we will remove the meta box and then we will add a new one again:

function customposttype_image_box() 
{
  // remove
  remove_meta_box( 'postimagediv', 'post', 'side' );

  // add
  add_meta_box('postimagediv', 'Here we here', 'post_thumbnail_meta_box', 'post', 'side', 'low');
  }
add_action('do_meta_boxes', 'customposttype_image_box');

How to merge one or more images

- (UIImage *)combineImage:(UIImage *)imageA imageB:(UIImage *)imageB 
{
  UIGraphicsBeginImageContext(imageA.size);

  [imageA drawInRect:CGRectMake(0, 0, imageA.size.width, imageA.size.height)];
  [imageB drawInRect:CGRectMake(0, 0, imageB.size.width, imageB.size.height)];

  UIImage *combinatedImage = UIGraphicsGetImageFromCurrentImageContext();

  UIGraphicsEndImageContext();

  return combinatedImage;
}
Read More

Let’s see some useful method about NSURL

Return the name of a file (with or without extension) from NSURLRequest:

- (NSString *)getFilenameFromRequest:(NSURLRequest *)request avoidExtension:(BOOL)avoidExtension 
{
  NSString *filePath = [[[request URL] path] lastPathComponent];
    if (avoidExtension) {
      NSArray *a = [filePath componentsSeparatedByString:@"."];
      return [a objectAtIndex:0];
    }
  return filePath;
}

Return the file extension from NSURLRequest:

- (NSString *)getExtensionFromRequest:(NSURLRequest *)request 
{
  NSString *filePath = [[[request URL] path] lastPathComponent];
  NSArray *a = [filePath componentsSeparatedByString:@"."];
  return [a objectAtIndex:1];
}

Finally, How to convert an address from NSString to NSURL and vice versa:

// filename
NSString *filePath = @"/path/filetext.txt";

// NSString to NSURL
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: filePath]; // do release

// or
NSURL fileURL = [NSURL fileURLWithPath: filePath]; // autorelease

// NSURL to NSString
NSString *filePath = [fileUrl absoluteString];

You can include a page/post content into a different page/post. For example, if you have a privacy disclaimer may be useful to load that content in a different context. This could be very useful when:

  • Anyone can edit the page/post without edit the included content
  • The loaded content works as standalone page/post as well

The best way to include a page/post content is:

$postID = get_page_by_title( "Privacy" )->ID;
$post = get_post( &$postID );
echo apply_filters( "the_content", $post->post_content );

You love Chroma Key, don’t you? As you know, this method is used to replace a background color with what you want. Today this technique is used everywhere also where you don’t expect. Have a look at the video below.

Read More

Many developers use the HTML comment in order to analyse the page by using the “view source” feature provided by almost all browsers. However, these comments will be visible to everyone. Also, they are sent from the server to the client and that could take a lot of needless bytes.

If you don’t need to display your HTML comment by using “view source” of if you don’t want to make visible them for all users, you might use the following simple rule:

<!-- Hi there,
     I'm an HTML comment
-->

The above HTML code is a comment. You can replace that by following:

<!-- <?php
Hi there,
I'm a "invisible" comment
?>
-->

or

<?php
// Hi there,
// I'm a "invisible" comment
?>

That’s all.

Currently, Objective-C does not support a class that provides a simple way to generate a random number. Anyway, we can use some C functions like: rand(), srand(), random(), srandom() e arc4random().

Read More

If you have used a custom query ( for example with query_posts()) before standard WordPress flow, you might reset the internal query to avoid the strange result in the sidebar or other sides:

// reset all your custom query
wp_reset_query(); 

// now they waorks
get_sidebar(); 
get_footer();

NSTimer is used is several contexts. However, you have to careful when you are going to invalidate the variable. For example:

// myTimer is defined as global
myTimer = [NSTimer scheduledTimerWithTimeInterval: 5.0
  target:self
  selector:@selector(myTimerMethod)
  userInfo:nil
  repeats:YES];

//
- (void) myTimerMethod {
  // do ...
}

Usually, you will use:

[myTimer invalidate];

As you can see in the code above, the timer is switched off but the variable is unset, so it is dangerous. The best way could be:

if( myTimer != nil) 
{
  [myTimer invalidate];
  myTimer = nil;
}

or, in a global context:

if( myTimer != nil) 
{
  [myTimer invalidate];
  myTimer = nil;

  // wait 25 seconds and start timer again
  myTimer = [NSTimer scheduledTimerWithTimeInterval: 25.0
    target:self
    selector:@selector(myTimerMethod)
    userInfo:nil
    repeats:YES];
}