Wordpress

Limit selected categories to one in wordpress

if you need to limit the creator of posts in the number of selected categories to one then I have good news for you.

NOTE: This code just change checkbox to radio in category form and doesn't validate it in backend!

Add numerious for each wordpress widget in sidebar
<?php
/**
 * Add numerious for each widget in sidebar
 */
function htmlandcms_widget_classes($params) {
  static $classes;
  if (!isset($classes[$params[0]['id']])) {
    $classes[$params[0]['id']] = 1;
  } else {
    $classes[$params[0]['id']] += 1;
  }
  $params[0]['before_widget'] = "<div id='{$params[0]['id']}-{$classes[$params[0]['id']]}'>" . $params[0]['before_widget'];
  $params[0]['after_widget'] = $params[0]['after_widget'] . "</div>";
  return $params;
}
add_filter('dynamic_sidebar_params', 'htmlandcms_widget_classes');

Custom rewrite rules with pagination in wordpress

Sometimes we need to use $_GET params in custom pages for something like custom filter.
In my case i must create page with custom query_posts, filter this posts and glossary. In glossary links must look like site.com/glossary/a/ or site.com/glossary/b/

First we need to create page with slug 'glossary' and set permalink to Post name.
In theme directory copy page.php to page-glossary.php and put this code

Add rel="fancybox" to wordpress gallery

If you need to add rel="fancybox" in the standard wordpress gallery, then this is a lesson for you.
Firstly what we need to do, its enqueue fancybox script, add image sizes for thumbnail and big picture and change implementation of gallery shortcode by default.
So let's do it.

Wordpress random comment with link to post

Task to show random comment with link to post. The decision below. First we get all approved comments. If we have comments we get random number among of existing, then we print comment content, and put link to commented post. Thats all, we spent some time to do it and we hope our solution will be useful for you.   

Wordpress random comment with link to post

Task to show random comment with link to post. The decision below. First we get all approved comments. If we have comments we get random number among of existing, then we print comment content, and put link to commented post. Thats all, we spent some time to do it and we hope our solution will be useful for you.   

0 out of 10 based on 0 ratings.
Read more
Wordpress custom fields metabox creation without plugins

Sometimes we need to add a lot of specific custom fields to the post (may be even depending on post category). Standard wordpress custom field metabox doesn't look very friendly. Of course you can use some plugin, like Custom Field Template, but you should consider that any plugin is an extension which is maintained by one or couple authors. You will always depend on it. More over plugins add database tables, there are a lot of security reasons for doing everything in wordpress way, using just core functionality.