Open Source: Easy iOS RSS and Atom Feed Parser Library

Recently I posted about a great tutorial on making an iOS RSS reader.  That tutorial used the Gdata feed parse, but I just found out about an interesting library that looks like  simpler alternative.  The tutorial does a great job of explaining how to set up Gdata for RSS feeds, but things are simpler with this specialized RSS and Atom feed parsing library.

The library is known as MWFeedParser, and what makes it different is that MWFeedParser is designed specifically for Atom and RSS feeds returning different elements of the feed as specific Cocoa objects for easy manipulation in your program.

The project is from Michael Waterfall and the Github repository can be found here:
https://github.com/mwaterfall

Looks like a great alternative for those looking to use RSS feed data within their apps.

Read More: Open Source iOS Libraries And Tools

[via Under The Bridge]

©2011 iPhone, iOS 4, iPad SDK Development Tutorial and Programming Tips. All Rights Reserved.

.

DeliciousTwitterTechnoratiFacebookLinkedInEmail

Tutorial: Take Screenshots Within Cocos2D Games And Upload Them To Facebook

Getting noticed in the app store can be difficult, and moving up If you have got a great looking game, users may want to share screenshots with their friends, and that in turn could get you more downloads.  Facebook is a great way to do this, and I found a tutorial for Cocos2D games that makes this trivial.

The tutorial guides you through the steps of implementing the screenshot code in your Cocos2D game, and how to use the FBConnect library so your users can upload those pictures.

The tutorial is from Alfred R. Baudisch of Karnak Games and can be found here:
How to take in-game screenshots with Cocos2D and upload them to a Facebook album

Whether or not people actually use the sharing option is another thing — you’ll really need to create a great looking game or one specifically designed to have it’s images shared.

Read More: Cocos2D Examples And Tutorials

©2011 iPhone, iOS 4, iPad SDK Development Tutorial and Programming Tips. All Rights Reserved.

.

DeliciousTwitterTechnoratiFacebookLinkedInEmail

iPhone Balloon Game Programming Tutorial: Adding Retina Display Support

I have had several requests for updates to the iPhone action game programming tutorial, and among them was an update for retina display support.  So here is the process step-by-step for those looking to add retina display support to a game made with the Sparrow Framework.

This update goes through the process of creating the new images for the game, and updating the source code so that the images display at high resolution on the retina display.

Fortunately the Sparrow Framework makes it very easy for us to do this, and handles most of the required programming automatically.

Project Files

You can download the project files leading up to this tutorial here.

You can download the project including the HD images and retina display support here.

For those who prefer Github you can find the project here, the completed project is in the 7-BalloonGameTutorial folder.

Step 1 – Making The Images

Since my initial images were created for the smaller iPhone display size I needed to scale them up to twice their original size.

I decided to use a tool called SmillaEnlarger to do this, a free open source tool that uses a fractal algorithm to scale up images. In my testing it has actually done better on the types of images (non-photos) that I need to scale up, and the end result looks considerably better than using any of the filters built into Photoshop. I have even seen it stated that SmillaEnlarger provides better results than expensive Photoshop plugins.

You can find SmillaEnlarger here.

You simply drag and drop the images with enlargement selected and a scale of 200%. In order to use the larger display support of the Sparrow Framework you will need to add @2x to the name of your images.

In my settings with SmillaEnlarger for non-photographis I simply turned all the extra adjustments down to zero.

Do that for each image in the project.  After doing that I suggest re-saving the images after opening them in preview, not essential, but SmillaEnlarger tends to make oversized files.

Step 2 – Add Images Into The Xcode Project

For this step you can simply drag all the created images into the Xcode project under resources where all the original files are.

You can also add the images by ctrl-clicking and then selecting add resources, select the images, and import them into the project.

Step 3 – Turn On High Resolution Support In Game

The Sparrow Framework simply requires you to add one line of code at this point into the applicationDidFinishLaunch: method of your app delegate.

So open up BalloonGameTutorialAppDelegate.m, and in the first line within the applicationDidFinishLaunching: method add:

[SPStage setSupportHighResolutions:YES;

Your applicationDidFinishLaunching: method should now look similar to this:

(void)applicationDidFinishLaunching:(UIApplication *)application {

// Enable retina display support
[SPStage setSupportHighResolutions:YES];

SP_CREATE_POOL(pool);

Game *game = [[Game alloc] initWithWidth:320 height:480];
sparrowView.stage = game;
[sparrowView start];
[window makeKeyAndVisible];
[game release];

[SPAudioEngine start];

SP_RELEASE_POOL(pool);
}

Now Build and Run the project, and you should be able to see the game running in retina display mode, I added the words High Definition to the images included with the project to illustrate that the new higher definition images are indeed displaying.  You can also select Window->Scale->100% to make your simulator display 1:1 for the iPhone’s resolution which makes it excessively large, but allows you to easily see HD is indeed working.

Conclusion

If you cannot see the words high definition you may have the retina screen turned off in the simulator, which means that in the Mac OS X menu you need to make sure Hardware->Device->Phone (Retina) is selected.

That is all there is to it, it is a very painless process with the Sparrow Framework.

The first tutorial in this series can be found here:
iPhone Balloon Game Programming Tutorial

You might be wondering why I didn’t pack the images using texture packer like in the Sparrow Framework’s tutorial on hd support.  My reason for that is simply because we’re still adding images to the project, and rather than pack the images over and over again we will do that when we add the finishing touches to the project.

In the next tutorial we will add menus to the game.

©2011 iPhone, iOS 4, iPad SDK Development Tutorial and Programming Tips. All Rights Reserved.

.

DeliciousTwitterTechnoratiFacebookLinkedInEmail

Tool: Objective-C Code Generator For Faster App Development

Found a very interesting tool that I have been using today that is absolutely brilliant for anyone programming in Objective-C on iOS and Mac.  The tool is known as Accesorizer.

What this tool does is allow you to generate repetitive Objective-C code using fully customizable parameters.  It’s tough to explain exactly what this tool does as it is completely different from anything I have used before, and it will take awhile for me to exploit the power of this tool.

If I did have to explain it though, I would call it super code complete on steroids.

Looking through the quick start guide should give you a very good idea about the coolness of this tool.

This video from the creator might make things a bit clearer:

You can find a trial version on the Accessorizer homepage which lasts for 30 days.

One thing though — the app store now says I have it installed even when deleted.. so if you’re looking to use a gift card to buy Accesorizer in the Mac App Store like I was you might want to do that first.

A great timesaving tool for sure.

[via Cerebral Gardens]

©2011 iPhone, iOS 4, iPad SDK Development Tutorial and Programming Tips. All Rights Reserved.

.

DeliciousTwitterTechnoratiFacebookLinkedInEmail

Open Source: In App Location Maps Using Any Map Source

In the time that I have run this site, many open source projects have fallen by the wayside.  One project that has been active for over two years now, and kept up to date is the Route Me mapping library project.

What Route Me allows you to is use virtually any source for your in-app location maps while providing the same look and feel as the native iOS Map tiles.  Those sources can be Google Map alternatives such as OpenStreetMap.org,  Microsoft VirtualEarth , but what makes it especially useful is that you can use your own sources such as DBMap and MBtiles.

The project includes a number of samples demonstrating the extensive functionality of the library, more information on the supported formats, and it can be found on Github at:
https://github.com/route-me/route-me

It is a great library  if you ever have the need to include your own maps within an app.

Read More: Open Source iOS Libraries And Tools

[via Feeling Fine]

©2011 iPhone, iOS 4, iPad SDK Development Tutorial and Programming Tips. All Rights Reserved.

.

DeliciousTwitterTechnoratiFacebookLinkedInEmail

Update: iPhone Balloon Game Tutorial Updated

I’ve seen quite a few requests for an update to the iPhone balloon game programming tutorial.  It seems many beginners to the iOS SDK were have an issue with the “Base SDK Missing” error, and sought an update to the latest edition to the Sparrow Framework.

I have repackaged and checked every project using the latest official SDK (4.2.1) and they should now run easily.  I have also created a Github repository for those seeking an easier way to download the code.

I’ve also seen many requests for new features to be added to the tutorial.  In the next update I will be adding retina screen support, and after that support for menus, high score tables, and social sharing.

You can find the tutorial here:
Game Programming Tutorial – Beginners Action Game

I look forward to reading about any other feature suggestions that you may have.

©2011 iPhone, iOS 4, iPad SDK Development Tutorial and Programming Tips. All Rights Reserved.

.

DeliciousTwitterTechnoratiFacebookLinkedInEmail

Tool: Easily Gather Sprite Data For Box2D And Generate Cocos2D Code

Found out about a pretty cool tool for those looking to develop games using Box2D (especially if you’re using Cocos2D — but really good for anyone using Box2D) called SpriteHelper.  It is a notch above the other tools I’ve seen doing similar.

What the tool allows you to do is easily gather information on any sprite such as UV, the vertex positions, position of the sprite within another image (for those of you using spritesheets), and the dimensions of the sprite’s rectangle — but most importantly the tool allows you to easily drag and create an outline around the shape, telling you if your shape will work with Box2D, you can then use the generated data, or even generate the actual Cocos2D code for your Box2D shape. Check out this video demo/tutorial:

The tool is currently only 0.99 cents at the moment in the Mac App Store. No word on whether it will go up in price.

You can find it here:
SpriteHelper

What I think really makes this tool different is just the ease of use, and the small details added to the tool that make things a bit easier.  If you are using Box2D, and especially Box2D and Cocos2D this should be a good time saver.

Thanks to the creator Vladu Bogdan for mentioning it in the iPhone and iPad development forum.

©2011 iPhone, iOS 4, iPad SDK Development Tutorial and Programming Tips. All Rights Reserved.

.

DeliciousTwitterTechnoratiFacebookLinkedInEmail

How to Switch work in iPhone

This is the very simple example. In this example we will see how to Switch function worked.

Step 1: Create a View base application using template. Give the application name “SwitchON”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: xpand classes and notice Interface Builder created the SwitchONViewController class for you. Expand Resources and notice the template generated a separate nib, SwitchONViewController.xib, for the “SwitchON”.

Step 4: Open the SwitchONViewController.h file and make the following changes in the file.

#import <UIKit/UIKit.h>

@interface SwitchONViewController : UIViewController {

IBOutlet        UILabel *display;
IBOutlet UISwitch *switch1;
       
}

@property (nonatomic,retain) UISwitch *switch1;

@property (nonatomic,retain) UILabel *display;

(IBAction)messagedisplay:(id)sender;

Step 5: Double click the SwitchONViewController.xib file and open it to the Interface Builder. Now first drag the switch from the library and place it to the view window and drag the label from the library and place it to the view window. Select the label from the view window and bring up attribute inspector, give the Text name “Please Switch me OFF!” . Select the switch from the view window and bring up Connection Inspector, connect Value Changed to the File’s Owner icon and select messagedisplay:, Connect File’s Owner icon to the switch and select switch1. Now save it close it and go back to the Xcode.

Step 6: In the SwitchONViewController.m file make the following changes.

(IBAction)messagedisplay:(id)sender
{
        NSString *message1 = [[NSString alloc] initWithFormat:@"Please switch me OFF!"];
        NSString *message2 = [[NSString alloc] initWithFormat:@"Please switch me ON!"];
       
        if (switch1.on){               
                display.text = @"Please switch me OFF!";
                [message1 release];
        }
        else {  
                display.text = message2;
                [message2 release];
        }
       
}

Step 7: Now compile and run the application in the simulator.

You can Download SourceCode from here SwitchON

ImageRotate using touch in iPhone

This is the ImageRotate example . In this example we will see how to image rotate anywhere of the screen using touch.

Step 1: Create a View base application using template. Give the application name “ImageMove_iPhone”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Xpand classes and notice Interface Builder created the ImageMove_iPhoneViewController class for you. Expand Resources and notice the template generated a separate nib,ImageMove_iPhoneViewController.xib, for the “ImageMove_iPhone”.

Step 4: We need to add UIView class in the project. Select Classes -> Add -> New File -> Cocoa Touch Class -> Objective C class -> select UIView from the Subclass of. Give the file name “ImageMove”.

Step 5: We have added one resource in the Resources folder. Give the name of the resource “11.jpg”,”feder.jpg”.

Step 6: In the ImageMove.h file, we specified the superclass as a UIImageView. So make the following changes in the file:

#import <UIKit/UIKit.h>

@interface ImageMove : UIImageView {

}

Step 7: Open the ImageMov.m file , make the following changes in the file.

(id) initWithImage:(UIImage *)image {
        if (self = [super initWithImage:image]) {
                [self setUserInteractionEnabled:YES];
                [self setMultipleTouchEnabled:YES];
        } return self;
}

(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
        if ([touches count] == 1) {
                CGPoint newTouch = [[touches anyObject] locationInView:[self superview]];
                CGPoint lastTouch = [[touches anyObject] previousLocationInView: [self superview]];
               
                float xDif = newTouch.x lastTouch.x;
                float yDif = newTouch.y lastTouch.y;
                CGAffineTransform translate = CGAffineTransformMakeTranslation(xDif, yDif);
                [self setTransform: CGAffineTransformConcat([self transform], translate)];
        }
       
       
}

Step 8: In the the ImageMove_iPhoneViewController.h file we have import “ImageMove.h” file.

Step 9: Open the mageMove_iPhoneViewController.m file, we create ImageView and make it visible. So make the following changes in the file.

(void)viewDidLoad {
    [super viewDidLoad];
       
        ImageMove* imageMove = [[ImageMove alloc] initWithImage:[UIImage imageNamed:@"11.jpg"]];
        [imageMove setFrame:CGRectMake(110, 60, [imageMove frame].size.width,[imageMove frame].size.height)];
        [[self view] addSubview:imageMove];
        [imageMove release];
       
               
        ImageMove* imageMove1 = [[ImageMove alloc] initWithImage:[UIImage imageNamed:@"feder.jpg"]];
        [imageMove1 setFrame:CGRectMake(110, 200, [imageMove1 frame].size.width,[imageMove1 frame].size.height)];
        [[self view] addSubview:imageMove1];
        [imageMove1 release];
       

}

Step 10: Now compile and run the application in the Simulator.

You can Download SourceCode from here ImageMove_iPhone

Calculate StringLength in MacOS

This is the very simple example, in this program we will see how to calculate string length in MacOS.

Step 1: Create a Cocoa Application from Mac OS X . Give the application name “StringsLength”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: xpand the Other  Sources folder, then  you can see one file “main.m”. We need to make changes in this file.

Step 4: Open the main.m file and make the following changes in the file.

#import <Cocoa/Cocoa.h>

 int main(int argc, char *argv[])
 {
        char s1[250];
        char s2[250];
        printf("Enter string s1:\n");
        scanf("%s",&s1);
        printf("Enter string s2:\n");
        scanf("%s",&s2);
        if(strlen(s1) == strlen(s2))
        printf("Length of string s1 is equal to length of string s2\n");
        else if(strlen(s1) < strlen(s2))
        printf("Length of string s1 is less than length of string s2\n");
        else
        printf("Length of string s1 is greater than length of string s2\n");
               
        return NSApplicationMain(argc,  (const char **) argv);
}

Step 5: Now compile and run the example and see the output on the console.

You can Download SourceCode from here StringsLength

PageMove Using Touch

This is the PageMove application. In this application we will see, how to page move  using touch function.

Step 1: Create a Window base application using template. Give the application name  ”MovePage”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: xpand classes and notice Interface Builder created the  MovePageAppDelegate  class for you. Expand Resources and notice the template generated a separate nib, MainWindow.xib, for the “MovePage”.

Step 4: In this project we need add to two UIView class, so now select classes -> Add -> NewFile -> Cocoa Touch Class -> Objective-C class -> and select UIView from the Subclass of. After that select next and Give the file name “PageView”. Do it once again and and give the another file name “PDFView”.

Step 5: We need add QuartzCore.framework in the framework folder. Select frameworks -> Add -> Existing Frameworks -> and select QuartzCore.framework.

Step 6: Another thing we have add in the project, i.e one pdf file, so add pdf file in the Resource folder. Give the pdf name “monsooninfo.pdf”.

Step 7: Now open the PDFView.h file and add the NSUInteger, CGPDFDocumentRef class. So make the following changes.

#import <UIKit/UIKit.h>

@interface PDFView : UIView {

        NSUInteger PDFNumber;
        CGPDFDocumentRef pdf;
}

@property (assign) NSUInteger PDFNumber;

Step 8: Open the PDFView.m file and make the following changes.

(id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
       
                CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("monsooninfo.pdf"), NULL, NULL);
                pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
                CFRelease(pdfURL);
                self.PDFNumber = 1;
                self.backgroundColor = nil;
                self.opaque = NO;
                self.userInteractionEnabled = NO;
    }
    return self;
}

(void)drawRect:(CGRect)rect {
 
       
        CGContextRef context = UIGraphicsGetCurrentContext();
       
        CGPDFPageRef page = CGPDFDocumentGetPage(pdf, PDFNumber);
       
        CGContextTranslateCTM(context, 0, self.bounds.size.height);
        CGContextScaleCTM(context, 1, 1);
       

        CGContextSaveGState(context);
        CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFMediaBox, self.bounds, 0, true);
        CGContextConcatCTM(context, pdfTransform);
        CGContextDrawPDFPage(context, page);
        CGContextRestoreGState(context);
}

Step 9: Open the PageView.h file and make the following changes.

#import <UIKit/UIKit.h>
#import "PDFView.h"

@interface PageView : UIView {
        NSUInteger PDFNumber;
       
@private
        PageView *View1;
        PageView *View2;
        PageView *View3;
       
}
@property (assign) NSUInteger PDFNumber;

Step 10: Now double click MainWindow.xib file and open it to the Interface Builder. First drag the view from the library and place it to the window. Select the view icon from the mainwindow and bring up IdentityInspector and select the pageView class (See the figure 1). Now save it, close it and go back to the Xcode.

Figure 1: Interface Builder connection

Step 11: Now open the PDFView.m file and make the following changes.

(void)awakeFromNib
{
       
  View1 = [[PDFView alloc] initWithFrame:self.bounds];
        View2 = [[PDFView alloc] initWithFrame:self.bounds];
       
        self.backgroundColor = [UIColor blackColor];
       
        [self addSubview:View3];
       
        View3.PDFNumber = 2;
        [self addSubview:View1];
}

(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
        lastPos = [[touches anyObject] locationInView:self];
}

CGPoint vectorBetweenPoints(CGPoint firstPoint, CGPoint secondPoint) {
        CGFloat xDifference = firstPoint.x secondPoint.x;
        CGFloat yDifference = firstPoint.y secondPoint.y;
       
        CGPoint result = CGPointMake(xDifference, yDifference);
       
        return result;
}

CGFloat distanceBetweenPoints(CGPoint firstPoint, CGPoint secondPoint) {
        CGFloat distance;
       
                CGFloat xDifferenceSquared = pow(firstPoint.x secondPoint.x, 2);
               
                CGFloat yDifferenceSquared = pow(firstPoint.y secondPoint.y, 2);
       
                distance = sqrt(xDifferenceSquared + yDifferenceSquared);
        return distance;
       
}
CGFloat angleBetweenCGPoints(CGPoint firstPoint, CGPoint secondPoint)
{
        CGPoint previousDifference = vectorBetweenPoints(firstPoint, secondPoint);
        CGFloat xDifferencePrevious = previousDifference.x;
       
        CGFloat previousDistance = distanceBetweenPoints(firstPoint,
                                                                                                         secondPoint);
        CGFloat previousRotation = acosf(xDifferencePrevious / previousDistance);
       
        return previousRotation;
}

(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
        CGPoint currentPos = [[touches anyObject] locationInView:self];
       
        fingerDelta = distanceBetweenPoints(currentPos, lastPos)/2;
       
        CGPoint fingerVector = vectorBetweenPoints(currentPos, lastPos);
       
       
       
        if ([[filter valueForKey:@"inputTime"] floatValue] < 0.9)
        {      
                [self bringSubviewToFront:View1];
                [filter release];
                filter = nil;
                filter = [[CAFilter filterWithType:kCAFilterPageCurl] retain];
                [filter setDefaults];
                [filter setValue:[NSNumber numberWithFloat:((NSUInteger)fingerDelta)/100.0] forKey:@"inputTime"];
               
                CGFloat _angleRad = angleBetweenCGPoints(currentPos, lastPos);
                CGFloat _angle = _angleRad*180/M_PI ;          
                if (_angle < 180 && _angle > 120)
                {
                        if (fingerVector.y > 0)
                                [filter setValue:[NSNumber numberWithFloat:_angleRad] forKey:@"inputAngle"];
                        else
                                [filter setValue:[NSNumber numberWithFloat:-_angleRad] forKey:@"inputAngle"];
                       
                        View1.layer.filters = [NSArray arrayWithObject:filter];
                }
        }
}

(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{      
        if ([[filter valueForKey:@"inputTime"] floatValue] > 0.7)
        {
                View1.PDFNumber ++;
                [View1 setNeedsDisplay];
               
                View3.PDFNumber ++;
                [View3 setNeedsDisplay];
               
                View1.layer.filters = nil;
               
                [filter setValue:[NSNumber numberWithFloat:0.0] forKey:@"inputTime"];
               
               
                CAFilter *previousFilter = [[CAFilter filterWithType:kCAFilterPageCurl] retain];
                [previousFilter setDefaults];
                [previousFilter setValue:[NSNumber numberWithFloat:0.91] forKey:@"inputTime"];
               
                [previousFilter setValue:[NSNumber numberWithFloat: M_PI] forKey:@"inputAngle"];
        }
        else
        {              
               
        }
}

Step 12: Now compile and run the application in the simulator. See the figure 2

Figure 2: Output of the Example.

You can Download SourceCode from here MovePage

Easily display post titles with a custom length

The first thing to do is to create the function. Open your functions.php file and paste this code:

 function ODD_title($char) {
         $title = get_the_title($post->ID);
         $title = substr($title,0,$char);
         echo $title;
}

Now, you can use the function on your theme files. Just pass how many characters you want to display as a parameter. In the following exemple, only the first 20 chars of the title will be displayed:

<?php ODD_title(20); ?>

Thanks to Orange Dev Design for the tip!

Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!

Easily display post titles with a custom length

How to modify size of embedded videos

Simply paste the following code on your functions.php file. Don’t forget to adjust size on line 2 and 3.

function mycustom_embed_defaults($embed_size){
    $embed_size['width'] = 586; // Adjust values to your needs
    $embed_size['height'] = 500;

    return $embed_size;
}

add_filter('embed_defaults', 'mycustom_embed_defaults');

Credits goes to Shailan. Thanks for the cool tip!

Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!

How to modify size of embedded videos

Change WordPress “from” email header

This recipe is pretty easy to implement: Just paste the following code into your functions.php theme:

function res_fromemail($email) {
    $wpfrom = get_option('admin_email');
    return $wpfrom;
}

function res_fromname($email){
    $wpfrom = get_option('blogname');
    return $wpfrom;
}

add_filter('wp_mail_from', 'res_fromemail');
add_filter('wp_mail_from_name', 'res_fromname');

Thanks to KeenTricks for the cool tip!

Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!

Change WordPress “from” email header

How to redirect your homepage to the first post

To apply this tip, paste the code below to your homepage file (Most of the time it is named index.php). Please note that you’ll receive a PHP warning if you try to display anything before the wp_redirect() function on line 10.

<?php
/*
home.php (Blog Home Page):
Redirect To First Post
*/

if (have_posts()) {
    while (have_posts()) {
        the_post();
        wp_redirect(get_permalink());
    }
}
?>

Thanks to Ashton Sanders for the tip!

Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!

How to redirect your homepage to the first post