Custom WordPress function to check page parent

— Quick update to the is_subpage() function. Basically it’s does the same but now it also accepts an integer to check if the current page is a child of certain ID. This way its easier to track if the current location is a subpage of a certain page. If it matches it will return a true value otherwise, it will be false.

→ Download the function here
function is_subpage( $iID = null )
	{
		global $post, $wpdb;

		if ( is_page() AND isset( $post->post_parent ) != 0 )
		{
			$aParent = $wpdb->get_row( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE ID = %d AND post_type = 'page' LIMIT 1", $post->post_parent ) );

			if ( is_int( $iID ) > 0 )
				if ( $aParent->ID == $iID ) return true; else return false;
			else
				if ( $aParent->ID )	return true; else return false;

		}
		else
		{
			return false;
		}
	}

/* EXAMPLE */

if ( is_page('producs') OR is_subpage( 8 ) )
{
  //do something
};

Cheers!

Tags: ,

Sunday, April 12th, 2009 WordPress 4 Comments

is_subpage() – Custom Conditional Function

— Quick conditional function for WordPress to check if the current page is a sub page. It works both inside and outside the main loop, only for 2.5 and upwards.

→ Download the function here

Example

Same way as you use is_page, is_home, etc.

< ?php if (have_posts()) : ?>

	< ?php while (have_posts()) : the_post(); ?>

		< ?php if ( is_subpage() ): ?>
			<p> This is a subpage </p>
		< ?php endif ?>

	< ?php endwhile; ?>

› Continue reading

Tags: , ,

Saturday, November 29th, 2008 WordPress 24 Comments

WordPress SEO: Control Search Engines

— When you build up a website you should keep in mind how you´ll want search engines to index your content. The main reason you’ll want to take control is to get all the juice out of your content and prevent possible indexing problems. Although this apply for all sites in this article I’m going to focus in a WordPress based site situation.

Why you should control search engines

It’s very important to know what and how you want search engines to index your site, if you don’t take the time to do it you are relying on them to “figure it out” for you, and that is not good. In a default WordPress installation you get different instances of your content repeated trough the site. For example take a post. It will appear in the homepage, in it’s single version, listed under a category, in the author pages, in search result, etc. Are you comfortable having duplicated content indexed and letting Search Engines pick/guess which version of it is the one you consider the most relevant? I bet you wont. Thats why it’s good to take this into consideration.
› Continue reading

Tags: , ,

Monday, November 24th, 2008 WordPress 11 Comments
« Previous Entries

About Me

Matt Varone - Matias Varone - sksmatt
HI there,

I'm a freelance creative web developer, UI designer and WordPress lover.

Twitter Status

Flickr Gallery

    Clutter drawerCS4 Replacement iconsCS4 Replacement iconsMagic

Scrnshots Gallery

  • Screenshot from ScrnShots.com
  • Screenshot from ScrnShots.com
  • new site im working on
  • Screenshot from ScrnShots.com