WordPress.org

Ready to get started?Download WordPress

Forums

How to access the Category description? (15 posts)

  1. alca11
    Member
    Posted 3 years ago #

    Hello fellas!

    When I edit a category, I see there's a field where I can type in a description about that category. Now I want to have this description in my sidebar on my site, but my theme doesn't support it – it just shows the same sidebar under each category, that is also on my front page.

    Anyone? :)

  2. esmi
    Forum Moderator
    Posted 3 years ago #

  3. alca11
    Member
    Posted 3 years ago #

    Thanks man! That's what I was looking for.
    It works fine for each category, but what if I wan't to have a certain content for the front page (home)?

    My template contains these files to be edited in the editor:

    (single.php)
    (footer.php)
    (header.php)
    (index.php)
    (comments.php)
    (searchform.php)
    (search.php)
    (page.php)
    (sidebar.php)
    (functions.php)
    (loop.php)
    (thememagic_functions.php)
    (thememagic_options.php)
    (style.css)

  4. esmi
    Forum Moderator
    Posted 3 years ago #

    Something like:

    <?php if( is_category() ) echo category_description();?>

    in sidebar.php should work.

  5. alca11
    Member
    Posted 3 years ago #

    Awesome man! That worked!
    Now the only problem is, that the descriptions don't have the same formatting as the front page sidebar.
    How do I access a class in the style.css, (for example the widget-formatting) and apply it to the description? http://www.emillyngbo.dk/category/photography
    There are no left-margins under the categories' descriptions now.

    <?php if( is_category()) { 
    
    	echo "<div class='widget-formatting'>" . category_description() . "</div>"; }
    	// this is where I want the widget-container formatting from the style.css file
    
    else {
    
    	if ( ! dynamic_sidebar( 'primary-widget-area' ) ) : ?>
    		<?php endif; // end primary widget area 
    
    }
    ?>
  6. esmi
    Forum Moderator
    Posted 3 years ago #

    I can't see the generated code for that markup in your sidebar.

  7. alca11
    Member
    Posted 3 years ago #

    Ok, is there a way I can find it to you?

  8. esmi
    Forum Moderator
    Posted 3 years ago #

    Where is this code being used on your site?

  9. alca11
    Member
    Posted 3 years ago #

    sidebar.php

    I put in the if/then statement in the beginning, to let php choose to show the category description, when on a category page, and the standard widget area, when on the frontpage. However, the category description looks kinda wrong formattet, as if it doesn't have the same left-margins as the frontpage, if you understand?

  10. esmi
    Forum Moderator
    Posted 3 years ago #

    Your theme's stylesheet doesn't seem to by applying any special CSS to .widget-formatting, so you could just add the CSS you want to use to a new rule - #sidebar .widget-formatting - in your stylesheet

  11. alca11
    Member
    Posted 3 years ago #

    But this piece of code sits inside of style.css:

    [CSS moderated as per the Forum Rules. Please just post a link to your site.]

    And seems to apply to the frontpage sidebar. Is there a way to make it apply to each category's sidebar as well?

    This piece of code in my previous post, was something I add'ed myself, whereas the div, don't seem to have any effect:

    echo "<div class='widget-formatting'>" . category_description() . "</div>"; }

  12. esmi
    Forum Moderator
    Posted 3 years ago #

    Try adding #sidebar .widget-formatting to that CSS.

  13. alca11
    Member
    Posted 3 years ago #

    Okay, so instead of a class, I added a ID for the div, and now it seems to respond to the .css file, when just do something like #sidebar {whatever formatting} in the css file.

    But my only problem left here, is when I go to categories -> description, I wan't to put in some pictures (to be contained in my description sidebars), but the description seems to only tolerate basic formatting like <b><i><u>. Is there a way around this, so that I can get a certain picture in each category sidebar?

  14. esmi
    Forum Moderator
    Posted 3 years ago #

    You could try looking for a plugin that adds an editor to the category description.

  15. alca11
    Member
    Posted 3 years ago #

    Okay cool. Didn't know that exited, will look for that.
    Anyway. Thanks a lot for your help.

Topic Closed

This topic has been closed to new replies.

About this Topic