wpGeek

Posts Tagged ‘Wordpress’

So I needed a function for which would check whether page has subpages/childrens or not. So I came up with this:

Just put this code in functions.php:
function post_have_children($id){
$children = get_pages('child_of='.$id);
if(count($children) == 0){
return false;
}
else{
return true;
}
}

Ussage:

<?php post_have_children('pageID'); ?>

pageID – the id of the page you want checked, can be used $post->ID which would be current page.

Note: check the quotes, because sometimes when doing copy paste they can be copied as symbols.

Furthermore, if you want to check if parent page has subpages/childrens or page has a parent as a conditional tag you can that by using it like this:

<?php if ( $post->post_parent != 0 || post_have_children($post->ID) ) {
// Show text if page has a parent or Page is a parent and have children/subpages
} ?>

Tags: , , ,

During my work as a wordpress theme coder I came across that there are request for a function on how to limit the post titles. So here you are the code and hope that it will be useful for you:

Open functions.php in your theme and copy/paste this code:

<?php function limit_title($title, $n){
if ( strlen ($title) > $n )
{
echo substr(the_title($before = ”, $after = ”, FALSE), 0, $n) . ‘…’;
}
else { the_title(); }
}
?>

Then just put this function where you want in your wordpress theme templates:

<?php limit_title($post->post_title, 30); ?>

Note:

  • Number in the gaps means to how much symbols you want to limit
  • The function should be used in the post loop

Tags: , , ,

Creating a WordPress theme from scratch is not hard. I’ll hold your hand through it.

Tutorials on this topic is being written while you reading this post and the WordPress website also has guides for you to follow. But are those tutorials and guides really helpful to you when you don’t understand the lingo? Even I got lost while reading the WordPress guides.

Tools – Before we get started, you’ll need:

  • WordPress installed on your computer. Follow the instructions on Installing WordPress Locally Under Windows XP. If you can’t install WordPress on your computer for whatever reason, no worries, just make a dummy WordPress install on your website.
  • Notepad or other text editors. I use Notepad ++, you can find it at www.downloads.com.
  • SmartFTP – If you’ll be testing your theme online, I’d suggest that you download and install SmartFTP or another FTP program to upload your theme files.
  • Bookmark XHTML Validator and CSS Validator. You’ll need those tools to validate your theme. They also come in handy when you need to spot and fix errors.

Tags: