Web Design, 3d & More - Aaron Newton 

Using body_class() in PODS CMS for Wordpress

 

I have been playing around with a CMS plugin for Wordpress called PODS. Here is a function for functions.php which might come in useful if you want to add POD page URL variables and page pod types to your body class:

 

 

function pods_body_class($classes)

{

    global $pods;

    if ( is_pod_page() )

    {

        $classes[] = "pod";

        if( is_object($pods) )

        {

            $classes[] = "pod-".$pods->datatype;

        }

 

        $classes[] = ' '.pods_url_variable(-2).' '.pods_url_variable('last');

    }

    return $classes;

}

 

add_filter('body_class','pods_body_class');

 

 

The body_class function is a useful built in Wordpress function that prints the page_id, blog post category etc. to the class names for the body element. It can be implemented like so:

<body <?php body_class(); ?>>

When implemented with the above code, this will return the last two URL variables, i.e. for the rewritten URL example/parent/child/. If the POD was 'cars' this would return body class names like this:

pod  parent child

If you assign corresponding class names to your sub-navigation elements (e.g. <ul class="parent">) you can then use CSS to highlight active menus like so:

.parent .parent { font-weight:bold };

Enjoy!

 

Posted by Aaron Newton 

Comments (3)

Jul 26, 2010
 said...
thanks! It actually doesn't work with the Hybrid Theme Framework :( but your Code helped me out anyway!
Jul 26, 2010
 said...
to make it work with hybrid, just change:

• all the "$classes[] =" to "$classes .="
and
• add_filter('body_class','pods_body_class'); to add_filter('hybrid_body_class','pods_body_class');

Regards

Dec 08, 2010
Aaron Newton said...
Cheers for the update Timo

Leave a comment...



Contact Us   |