Forums

How to add different icons per article category. (5 posts)

  1. thinkingleft
    Member
    Posted 1 year ago #

    Hi,

    I'm trying to get some icons in front of my article titles on the homepage, and a different icon per category (there will just be around 5 of them), but I don't really know where to start.

    A friend of mine told me the following:
    Add this to the index.php:

    <div class="<?php
    $cats = get_the_category();
    echo $cats[0]->category_name;
    ?>"></div>

    where category_name is the name of the category ;) duh.
    And then style with:
    .category-name in de css (so add and place image).

    But I don't know where to put the php in the index.php.

    Can someone please get me into the right direction?
    Very much appreciated!
    david.

    p.s.: I'm using the thematic theme.

  2. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    it would go right before your title call....

    <div class="titleText"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></div>

    is how mine looks

    you would then need to use css to position everything

    I would recommend doing this with the above code:

    <div class="catimage <?php
    $cats = get_the_category();
    echo $cats[0]->category_name;
    ?>"></div>

    see how I added catimage in there? That way you have a class of catimage as well as each category..

    So you can use .catimage in your css to position the images.... anyrthing you do to .catimage will affect all the icons, so you can get them all nice and lined up with that

    Then use .category-name to just insert the icons, that way you don't need to repeat the positioning css with each category

  3. thinkingleft
    Member
    Posted 1 year ago #

    Hi Voodoo,

    Sorry for the late reaction. Hmz.. have to check if I can't get email updates on replies.

    Thank you a bunch mate! Will get on it right now and will keep you posted! Thanks for taking time to explain it to me. Very much appreciated! =)

    Hope you are enjoying your weekend. =)

    david.

  4. thinkingleft
    Member
    Posted 1 year ago #

    Hi, I've been looking for a similar line in my php files, but I can't find anything. This is my index.php and well.. it looks pretty basic.

    <?php
    
        // calling the header.php
        get_header();
    
        // action hook for placing content above #container
        thematic_abovecontainer();
    
    ?>
    
    	<div id="container">
    		<div id="content">
    
    			<?php 
    
                // create the navigation above the content
                thematic_navigation_above();
    
                // calling the widget area 'index-top'
                get_sidebar('index-top');
    
                // action hook for placing content above the index loop
                thematic_above_indexloop();
    
                // action hook creating the index loop
                thematic_indexloop();
    
                // action hook for placing content below the index loop
                thematic_below_indexloop();
    
                // calling the widget area 'index-bottom'
                get_sidebar('index-bottom');
    
                // create the navigation below the content
                thematic_navigation_below();
    
                ?>
    
    		</div><!-- #content -->
    	</div><!-- #container -->
    
    <?php 
    
        // action hook for placing content below #container
        thematic_belowcontainer();
    
        // calling the standard sidebar
        thematic_sidebar();
    
        // calling footer.php
        get_footer();
    
    ?>

    So where would I copy the code you wrote above?

    Thanks again!

  5. thinkingleft
    Member
    Posted 1 year ago #

    Small update:

    I think I need to add something in the content-extentions.php file.
    Is this correct?

    somewhere near:

    // Create the post edit link
    function thematic_postheader_posteditlink() {
    
        global $id;
    
        $posteditlink = '<a href="' . get_bloginfo('wpurl') . '/wp-admin/post.php?action=edit&post=' . $id;
        $posteditlink .= '" title="' . __('Edit post', 'thematic') .'">';
        $posteditlink .= __('Edit', 'thematic') . '</a>';
        return apply_filters('thematic_postheader_posteditlink',$posteditlink); 
    
    } // end thematic_postheader_posteditlink
    
    // Create post title
    function thematic_postheader_posttitle() {
    
        if (is_single() || is_page()) {
            $posttitle = '<h1 class="entry-title">' . get_the_title() . "</h1>\n";
        } elseif (is_404()) {
            $posttitle = '<h1 class="entry-title">' . __('Not Found', 'thematic') . "</h1>\n";
        } else {
            $posttitle = '<h2 class="entry-title"><a href="';
            $posttitle .= get_permalink();
            $posttitle .= '" title="';
            $posttitle .= __('Permalink to ', 'thematic') . the_title_attribute('echo=0');
            $posttitle .= '" rel="bookmark">';
            $posttitle .= get_the_title();
            $posttitle .= "</a></h2>\n";
        }
        return apply_filters('thematic_postheader_posttitle',$posttitle); 
    
    } // end thematic_postheader_posttitle
    
    // Create post meta
    function thematic_postheader_postmeta() {
    
        $postmeta = '<div class="entry-meta">';
        $postmeta .= thematic_postmeta_authorlink();
        $postmeta .= '<span class="meta-sep meta-sep-entry-date"> | </span>';
        $postmeta .= thematic_postmeta_entrydate();
    
        $postmeta .= thematic_postmeta_editlink();
    
        $postmeta .= "</div><!-- .entry-meta -->\n";
    
        return apply_filters('thematic_postheader_postmeta',$postmeta); 
    
    } // end thematic_postheader_postmeta

    thanks again.

Topic Closed

This topic has been closed to new replies.

About this Topic