Adding a class to element in page template?

Community Forums Forums General Discussion Adding a class to element in page template?

This topic is: not resolved

This topic contains 3 replies, has 2 voices, and was last updated by  rfmeier 1 year, 2 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #44478

    hadhops
    Participant
    Post count: 1

    Hello,

    I have very little knowledge of php and need to add a class to an element so I can style it.

    Basically I want the category name to appear at the top of the page before the content-sidebar div. I’ve managed to piece together bits and peices to achieve this, however there I need a class on the category.

    Here is my page template code (I’ve bolded the relevant function and action)-

    <?php
    /*Template Name Posts: Faculty Post*/
    ?>

    <?php

    add_action( ‘genesis_meta’, ‘faculty_post_genesis_meta’ );
    /**
    * Add widget support for this template. If no widgets are active, display the default Genesis loop.
    *
    */
    function faculty_post_genesis_meta() {

    if ( is_active_sidebar( ‘Sidebar’ ) ) {

    remove_action( ‘genesis_loop’, ‘genesis_do_loop’ );
    add_action( ‘genesis_before_content_sidebar_wrap’, ‘ducere_the_category’ );
    add_action( ‘genesis_loop’, ‘genesis_do_loop’ );
    add_filter( ‘body_class’, ‘add_body_class’ );

    function add_body_class( $classes ) {
    $classes[] = ‘faculty_post’;
    return $classes;
    }

    function ducere_the_category() {
    $category = get_the_category();
    echo $category[0]->cat_name;

    }
    }

    }

    genesis();

     

    Thank you for any help :)

    http://martinhadley.com/ducere/?p=164
    #44493

    rfmeier
    Participant
    Post count: 596

    Hello,

    I tried a quick example for a single post within my development environment. You can try the code below within your template file.

    Since you are using a template, WordPress should automatically insert a css class into the body element that is a slug of your template.

    Let me know how it turns out.


    #44500

    hadhops
    Participant
    Post count: 1

    You nailed it! Thank you so much.

    #44503

    rfmeier
    Participant
    Post count: 596

    You are welcome. Glad I could help.


Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.