WordPress.org

Ready to get started?Download WordPress

Forums

Define class and id using php (5 posts)

  1. Alex Cragg
    Member
    Posted 7 years ago #

    i recently altered my comments.php to highlight alternate posts different colours, and also when i wrote a comment, to highlight that a different colour too. I used some code i found in the support forum for the alternate highlighting, and the Author Highlight plugin for highlighting my comments.

    to achieve this, i gave the li tag a class and an id, i created the li class and id like this
    <li class="<?php echo $oddcomment; ?>" id="<?php author_highlight(); ?>">

    where the $oddcomment variables had been defined before.

    what i now want to know is, is it possible to create a plugin that would define the class and the id of the li tag in one go, as opposed to two sections.
    so you'd end up with something like this
    <li <?php admin_alt_highlight(); ?>
    which would create an output like
    <li class="alt" id="author">

    any pointers much appreciated

  2. Alex Cragg
    Member
    Posted 7 years ago #

    anyone know if this sort of stuff is possible?

  3. pizdin_dim
    Member
    Posted 7 years ago #

    You need to keep in mind that in CSS and "id" attribute must be unique, so this is actually invalid, unless there's only one comment made by the author:

    <li class="alt" id="author">

    I'm assuming from what you're saying that you want to be able to somehow highlight any comments by the author of the post. If so, the above is only good if the author leaves only one comment, which is impractical.

    Perhaps a better solutions is to use multiple classes (instead of a class and an id) instead.

  4. Alex Cragg
    Member
    Posted 7 years ago #

    @pizdin_dim - i realized that after i posted this topic(thanks to the validator), and i changed it straight away on my current theme.

    mod look added for jmcpherson421 posts...pretty weird posts IMO.

    so im not really any closer...

    ill phrase it differently,

    i would like to know how to generate 2 class out puts in 1 php call.

  5. pizdin_dim
    Member
    Posted 7 years ago #

    Instead of <li class="alt" id="author"> use <li class="alt author">

Topic Closed

This topic has been closed to new replies.

About this Topic