Support » Themes and Templates » Odd and even css for links.php

  • Okay so I’m trying to sort out my links page. One of the things I’d like to do is the have different coloured backgrounds for each link that alternate.

    So a bit of a google search and I found out about the odd and even function calls. Nice, so it’s been done before sucessfully, cool.

    Now I’m calling the links via the get_links_list() function. This function is found in the wp-includes folder, under links.php

    Does anyone know how to implement this?
    I’m thinking this is the code that needs to be played around with. How do I get the table code incorporated?


Viewing 5 replies - 1 through 5 (of 5 total)
  • See I’m not sure where to put that code now. If I put it in my static page it won’t work.

    Leaving me to put it in my links.php, and this is where I’m having a bit of trouble.

    I’ve looked around a bit more, and came to elasticdog’s use of the codeviewer, which is pretty much spot on. He’s using lists and everthing.

    The thing is I don’t understand his arguements here. He’s got toggle in the css. I’m not following, I know this is supposed to be easy but I’m just not seeing it tonight.

    Trying Scripty’s code, I’ve added the function to the links.php code, but now the question is where do I put the <p class=….. etc ?

    I am actually implementing this feature into my wp-exec plugin. Basically allowing you to embed links inside posts or pages, dynamically.

    That’s not exactly what I’m looking for Navid, although that’s pretty cool as well, I’m actually just looking for the code that will make the links that show up using get_links_list to alternate background colour.

    Okay I’m trying to implement scripty’s code, just faltering at one point. I’ve put the following function (as is, just above the file begining of the get_links_list function begins) in the links.php file

    function comment_style() {
    static $comment_count;
    if ($comment_count % 2) {
    echo "odd";
    else {
    echo "even";

    I’ve sorted out the classes in the css, for odd and even.

    It’s this last part that I really could use some help with, how do you incorporate the call within the function? Ie where do I put

    class="<? comment_style(); ?>"

    to the ol list?

    I’ll reproduce the links function:

    function get_links_list($order = 'name', $hide_if_empty = 'obsolete') {
    global $wpdb;

    $order = strtolower($order);

    // Handle link category sorting
    if (substr($order,0,1) == '_') {
    $direction = ' DESC';
    $order = substr($order,1);

    // if 'name' wasn't specified, assume 'id':
    $cat_order = ('name' == $order) ? 'cat_name' : 'cat_id';

    if (!isset($direction)) $direction = '';
    // Fetch the link category data as an array of hashesa
    $cats = $wpdb->get_results("
    SELECT DISTINCT link_category, cat_name, show_images,
    show_description, show_rating, show_updated, sort_order,
    sort_desc, list_limit
    FROM $wpdb->links
    $wpdb->linkcategories ON (link_category = cat_id)
    WHERE link_visible = 'Y'
    AND list_limit <> 0
    ORDER BY $cat_order $direction ", ARRAY_A);

    // Display each category
    if ($cats) {
    foreach ($cats as $cat) {
    // Handle each category.
    // First, fix the sort_order info
    $orderby = $cat['sort_order'];
    $orderby = (bool_from_yn($cat['sort_desc'])?'_':'') . $orderby;

    // Display the category name
    echo ' <li id="'.sanitize_title($cat['cat_name']).'">' . $cat['cat_name'] . "nt<ul>n";
    // Call get_links() with all the appropriate params

    // Close the last category
    echo "nt</ul>n</li>n";

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Odd and even css for links.php’ is closed to new replies.