WordPress.org

Forums

assigning classes to tags: How? (17 posts)

  1. FionaDixit
    Member
    Posted 10 years ago #

    Hi all,

    I need to apply 2 classes to 2 tags but I am unsure how.

    '<p class="posted">
    <?php smart_comments_popup_link('Want to reply?', '1 Comment', '% Comments'); ?>
    |
    <?php _e("Filed under:"); ?> <?php the_category(',') ?>'

    I would like to apply a class to the a href of the tags smart comments and the category.

    I am not 100% sure how I do this though. Can youi help please?

    Thanks a bunch
    F

  2. Mark (podz)
    Support Maven
    Posted 10 years ago #

    .posted {
    color:#ff0000;
    }

    That will turn the text red - add whatever else you wish.
    That okay ?

  3. FionaDixit
    Member
    Posted 10 years ago #

    Ah sorry Podz - I mean't I want to assign a class to the 'category' tag called 'class 1' for example and to the 'comments popup' 'class 2'. and then remove the 'posted' tag

    Can I do that? I thought I could do that in the () of the corresponding tags but I am unsure how.

    Thank you

  4. Mark (podz)
    Support Maven
    Posted 10 years ago #

    '<div class="class1">
    <?php smart_comments_popup_link('Want to reply?', '1 Comment', '% Comments'); ?></div>
    |
    <div class="class2">
    <?php _e("Filed under:"); ?> <?php the_category(',') ?>
    </div>`

    .class1 {
    color: #ff0000;
    }

    .class2 {
    color: #0000ff;
    }

    That would work .. but linebreaks may happen..

  5. FionaDixit
    Member
    Posted 10 years ago #

    Thanks for that Podz :)

    So I guess I can't do it inline then like this:

    'Want to reply?'

    Sorry to be a pain but I would like it like this if possible.

    Sorry and thanks so far :)

  6. FionaDixit
    Member
    Posted 10 years ago #

    'a href="http://www.domain.com/archives/#comments" class="classname_here">Want to reply?</a'

  7. Kafkaesqui

    Posted 10 years ago #

    Use the <span> tag (in place of <div>) for inline stuff.

  8. FionaDixit
    Member
    Posted 10 years ago #

    Hi Kafkaesqui,

    Where would I put it in '<?php smart_comments_popup_link('Want to reply?', '1 Comment', '% Comments'); ?>' ?

    Thanks :)

  9. Kafkaesqui

    Posted 10 years ago #

    Just replace the div that podz used in his example:

    <span class="class1">
    <?php smart_comments_popup_link('Want to reply?', '1 Comment', '% Comments'); ?></span>

  10. FionaDixit
    Member
    Posted 10 years ago #

    Hi there,

    sorry it's still not what I am after - I want to put the class withing the a href tag of smart_comments_popup_link

    I guess that can't be done unless I hard code. What file deals with this code?

    Thanks
    Fiona

  11. Root
    Member
    Posted 10 years ago #

    I suspect that the real issue here is that you want to restyle the link. Further presentational markup would not normally be necessary to do that. If you have a url we can take a stab at the selector.

  12. Kafkaesqui

    Posted 10 years ago #

    "I want to put the class withing the a href tag of smart_comments_popup_link. I guess that can't be done unless I hard code."

    Unfortunately that's correct. smart_comments_popup_link() is from a hack or plugin, depending on the version you've implemented, but it uses comments_popup_link() to generate the link, which is a function found in:

    wp-includes/comment-functions.php

    For 1.5 it should be around line 90 in that file. Look for:

    echo '<a href="';

    You can insert your class attribute there.

    Note: Back up source files before editing them, and comment your changes for future reference.

  13. Kafkaesqui

    Posted 10 years ago #

    So, would a plug for one of my plugins work here?

    http://guff.szub.net/add-link-attribute/

    This should let you make your additions without editing the source. However, it does require modifying your templates, i.e.:

    <?php add_link_attr('smart_comments_popup_link', 'Want to reply?, 1 Comment, % Comments', 'class="class1"'); ?>

  14. FionaDixit
    Member
    Posted 10 years ago #

    Hey Kafkaesqui,

    Thats pretty cool :)

    I just don't like to keep surround elements with spans on unnescasary divs.

    I will try this out and get back to you :)

  15. FionaDixit
    Member
    Posted 10 years ago #

    I think that might just do it :)

    I am not quite sure how to write the code for this one though:

    '<?php _e("Filed under:"); ?>'

    Thank you for all your assistance so far :)

  16. Kafkaesqui

    Posted 10 years ago #

    _e() is a localization function, and all it does it display the text it's holding as an argument (or translate and display it if you've localized WordPress into another language). If it needs styling beyond the div or p it's in, I think you're best off just sticking it in a span. I know, but I think my plugin would be overkill for wrapping that function, especially since you'll still need to place a div or span around it to style the text.

  17. FionaDixit
    Member
    Posted 10 years ago #

    No thats fine :)

    It did just the trick. Many thanks.

    That plugin is rather handy :)

    Thank you
    Fiona

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags