WordPress.org

Ready to get started?Download WordPress

Forums

More classes at previous_post_link (7 posts)

  1. Noisie
    Member
    Posted 1 year ago #

    At the moment my php knowledge isn't very high. Even then the WordPress CMS is very well build and easy to understand for a newbie.

    One thing im stuck on for a while now is the possibility to add extra classes to the previous_post_link and next_post_link.

    My code is like this atm:
    <?php previous_post_link( '%link', __( '<span class=icon-chevron-left></span> Vorige' ) ); ?>

    I would like to add another class to the string but when i use '.' like WordPress is using at other spots it will put the second class outside the class="".

    Can anyone help me with this issue? I think there sould be an simple solution for it.

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Why do you need to add an extra class?

  3. Noisie
    Member
    Posted 1 year ago #

    I am using the Bootstrap framework with WordPress and it uses object orientated css. I am a big fan of OOC because it will keep the CSS clean and structured when a website is growing large.

    In my specific case I am using a spriteset (glypthicons) what is already integrated in the Bootstrap framework. With the class=icon-chevron-left I call an arrow icon background image. With another class (icons-white) in my case i can make the background white.

    The quickfix would be to overwrite the bootstrap class in styles.css. But I want to prevent that since the best solution is a extra class so the stylesheets will be as slim as possible and the style.css wont get filled with unnecessary styles.

    I hope someone can help me out :)

  4. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    have you tried:

    <?php previous_post_link( '%link', __( '<span class="icon-chevron-left icons-white"></span> Vorige' ) ); ?>

    but when i use '.' like WordPress is using at other spots

    if the above does not work, could you post exactly what you have tried?

  5. Noisie
    Member
    Posted 1 year ago #

    That was the first thing I tried. When I put the code like that and inspect the code with firebug the output is like this:

    a rel="next" href="url..">Volgende <span icon-white="" class="icon-chevron-right"></span>/a

    I use WordPress 3.5 and the only relevant code I changed for the buttons is:
    <?php previous_post_link( '%link', __( '<span class=icon-chevron-left icons-white></span> Vorige' ) ); ?>

    In my functions.php I use extra code to put a class on the anchor:
    function single_btn_add_class($format){
    $format = str_replace('href=', 'class="btn btn-small btn-info" href=', $format);
    return $format;
    }
    add_filter('next_post_link', 'single_btn_add_class');
    add_filter('previous_post_link', 'single_btn_add_class');

    It seems so simple but ive been trying all sort of things and searching on the WordPress forums for similar cases.

  6. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    have you noticed and tried the double-quotes in my version:

    <span class="icon-chevron-left icons-white">

    vs your version:

    <span class=icon-chevron-left icons-white>

  7. Noisie
    Member
    Posted 1 year ago #

    It works now, thank you! When I tried the double-quotes my HTML editor is calling for a error in the code because of the 'at the span' but I ignored it now and it works without php errors :)

    EDIT: I have to say I tried to fill in single quotes what was triggering the error I understand now why next time I'll use double quotes.

Topic Closed

This topic has been closed to new replies.

About this Topic