Archive May, 2010

WordPress: retrieve the contents of a page

Sometimes it can be useful to include in a page the contents of another. For example if you have created a registration page and volote show in a box of privacy disclosures, it would be handy to be able to upload this content to an existing page. This has the advantage:

  • The customer can change the page content without "tocccare" the original page that contains
  • The page works well alone, so you can put in the footer of the site a link to "privacy" for example

The best way to include the contents of one or more pages is as follows:

1
2
3
get_page_by_title ( "Privacy" ) -> ID ; Postid = $ get_page_by_title ("Policy") -> ID;
get_post ( & $postID ) ; $ Post = get_post (& $ postid);
"the_content" , $post -> post_content ) ; echo apply_filters ('the_content', $ post -> post_content);

The ID of the post (the page in the example above) is obtained by its title both for clarity and for compatibility with export or re-index involuntary.

Continued ...

WordPress MU: get the ID of the current blog

Here are three ways to retrieve the ' ID of the current blog.

Through the global $blog_id

1
; echo $ blog_id;

Through the global object $current_blog

1
-> blog_id ; echo $ current_blog -> blog_id;

Through the global object $wpdbg

1
-> blogid ; echo $ wpdb -> blogId;

Continued ...

Customize the sections in a UITableView Grouped

potremmo aver necessità di personalizzare la grafica dei titoli delle sezioni, come California o New York dell'esempio qui sotto. When we use a UITableView style Grouped we may need to customize the layout of section titles, such as California or New York the example below.

UITableView

To do so, please use the following code, placing it in the delegate, ie in the class that responds to the protocol UITableViewDelegate :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/ / Returns View my custom, in this case an object
/ / Type UILabel
UIView * ) tableView : ( UITableView * ) tableView - (UIView *) tableView: (UITableView *) tableView
NSInteger ) section { viewForHeaderInSection: (NSInteger) section {

[ [ [ UILabel alloc ] initWithFrame : CGRectZero ] autorelease ] ; UILabel * label = [[[UILabel alloc] initWithFrame: CGRectZero] autorelease];
UIFont boldSystemFontOfSize : 20 ] ; label.font = [UIFont boldSystemFontOfSize: 20];
label.textAlignment = UITextAlignmentCenter;
UIColor blackColor ] ; label.shadowColor = [UIColor blackColor];
1 , 1 ) ; label.shadowOffset CGSizeMake = (1, 1);
"Sezione" ; // Sostituire con un array come al solito Label.Text @ = "Section", / / Replace with an array as usual
UIColor whiteColor ] ; label.textColor = [UIColor whiteColor];
UIColor clearColor ] ; label.backgroundColor = [UIColor clearColor];
; label.opaque = NO;

return label;
}
/ / We must also support this message does not work otherwise
CGFloat ) tableView : ( UITableView * ) tableView - (CGFloat) tableView: (UITableView *) tableView
NSInteger ) section { heightForHeaderInSection: (NSInteger) section {
; return 44;
}

It is also important to include heightForHeaderInSection , will not work.

Notes of interest

o UIImageView , ho utilizzato per inizializzare il frame CGRectZero che corrisponde a CGRectMake(0,0,0,0) . In the creation of our UILabel , which might also be wanting a more complex object like a UIView or UIImageView , I used to initialize the frame CGRectZero corresponding to CGRectMake(0,0,0,0) .

Continued ...

How to get Latitude and Longitude in Objective-C

The framework provides MapKit many useful features, except the return of Longitude and Latitude from an address. In JavaScript, for example, you can use the service provided by Google Geocoding and discussed in Google Maps: How to get Latitude and Longitude from an address . Apple iPhone or iPad, however, you can overcome this obstacle by using a different Google services. Specifically, you can call directly to the url:

1
http://maps.google.com/maps/geo?q = [address] & output = csv

Where is [indirizzo] to enter the string with the address you want to transform coordinates. The output returned is of type:

1
200,8,41.9128300,12.2241172

). The first value, 200 , indicates that everything went well ( 200 OK ). The second, 8 , Google is the accuracy parameter (1-10). The last two values ​​are, finally, latitude and longitude. Now we see a prototype of a method can be included in our applications:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
CLLocationCoordinate2D ) getLocationFromAddress : ( NSString * ) address { - (CLLocationCoordinate2D) getLocationFromAddress: ( NSString *) address {
urlString = [ NSString stringWithFormat : @ "http://maps.google.com/maps/geo?q=%@&output=csv" , NSString * urlString = [ NSString stringWithFormat: @ "% @ http://maps.google.com/maps/geo?q = & output = csv"
NSUTF8StringEncoding ] ] ; [StringByAddingPercentEscapesUsingEncoding address: NSUTF8StringEncoding]];

listItems = [ locationString componentsSeparatedByString : @ "," ] ; NSArray * ListItems = [locationString componentsSeparatedByString: @ ""];

/ / Int zoom = 0;
0.0 ; double latitude = 0.0;
0.0 ; double longitude = 0.0;

listItems count ] > = 4 && [ [ listItems objectAtIndex : 0 ] isEqualToString : @ "200" ] ) { if ([ListItems count]> = 4 & & [[ListItems objectAtIndex: 0] isEqualToString: @ "200"]) {
/ / Zoom = [[ListItems objectAtIndex: 1] intValue];
listItems objectAtIndex : 2 ] doubleValue ] ; Latitude = [[ListItems objectAtIndex: 2] doubleValue];
listItems objectAtIndex : 3 ] doubleValue ] ; longitude = [[ListItems objectAtIndex: 3] doubleValue];
{ Else {}
/ / Error
}
CLLocationCoordinate2D location;
location.latitude = latitude;
location.longitude = longitude;

return location;
}

Notes of interest

, alla stregua della funzione explode ( ) del PHP per intenderci. The string returned in locationString is "split" by the method componentsSeparatedByString , like the function explode ( ) in PHP for instance. I put the example I proposed - but commented - the code to retrieve even the Google accuracy parameter, precision or scale factor, denoted by zoom .

Source as

For completeness, I made ​​a small example application with which you can try the method proposed above, enter any address and the iPhone will show on the map.


Download Source

I thank the team devAPP for the inspiration of this article.

Continued ...


Stop SOPA