SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Guru Marubozo's Avatar
    Join Date
    Mar 2005
    Location
    Near South Bend, Indiana
    Posts
    657
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wordpress get_links() in version 2.2

    Quick question for anyone out there using 2.2+. When upgrading my blogroll function used to call only a specific link category and no longer works. Previously I had used this:

    PHP Code:
    <?php wp_list_bookmarks('categorize=0&category=17&title_li= '); ?>
    That would display only link category 17. In 2.2 that doesn't work, which I expected so I switched to the get_links function and tried it with this code:

    PHP Code:
    <?php get_links(17'<li>''</li>'' - '); ?>
    It doesn't display any links at all. But if I change 17 to -1 it will show all of the links just fine. Well that's fine and dandy, but I just want it to show one category in a particular area and I can't figure it out.

    Any ideas?
    Generation X Finance
    Helping a Unique Generation Achieve Financial Independence

    Financial Planning writer at About.com

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,426
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    get links

    The get_links function is in the includes/bookmark-template.php file
    PHP Code:
    /** function get_links()
     ** Gets the links associated with category n.
     ** Parameters:
     **   category (default -1)  - The category to use. If no category supplied
     **      uses all
     **   before (default '')  - the html to output before the link
     **   after (default '<br />')  - the html to output after the link
     **   between (default ' ')  - the html to output between the link/image
     **     and its description. Not used if no image or show_images == true
     **   show_images (default true) - whether to show images (if defined).
     **   orderby (default 'id') - the order to output the links. E.g. 'id', 'name',
     **     'url', 'description', or 'rating'. Or maybe owner. If you start the
     **     name with an underscore the order will be reversed.
     **     You can also specify 'rand' as the order which will return links in a
     **     random order.
     **   show_description (default true) - whether to show the description if
     **    show_images=false/not defined .
     **   show_rating (default false) - show rating stars/chars
     **   limit (default -1) - Limit to X entries. If not specified, all entries
     **     are shown.
     **   show_updated (default 0) - whether to show last updated timestamp
     **   echo (default true) - whether to echo the results, or return them instead
     */
    function get_links($category = -1,
                
    $before '',
                
    $after '<br />',
                
    $between ' ',
                
    $show_images true,
                
    $orderby 'name',
                
    $show_description true,
                
    $show_rating false,
                
    $limit = -1,
                
    $show_updated 1,
                
    $echo true) { 

  3. #3
    SitePoint Guru Marubozo's Avatar
    Join Date
    Mar 2005
    Location
    Near South Bend, Indiana
    Posts
    657
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but that doesn't help. I even tried going to the codex and using the example they give that says "Displays links for link category ID 2 in span tags, uses images for links, does not show descriptions, sorts by link URL."

    PHP Code:
    <?php get_links(2'<span>''</span>'''TRUE'url'FALSE); ?>
    I replace the number 2 with any of my link category IDs and it still doesn't work, yet I make it the default -1 and it works fine and displays them all.

    I just don't get how the simple act of changing a -1 to another number breaks the whole thing. I thought maybe I had the category number wrong but I even went into phpmyadmin to double check the database and it is clearly correct.
    Generation X Finance
    Helping a Unique Generation Achieve Financial Independence

    Financial Planning writer at About.com

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,426
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    string?

    I wonder if because the args are parsed from a string, the number needs to be in quotes (not an int). ie.
    PHP Code:
    <?php get_links('17''<li>''</li>'' - '); ?>

  5. #5
    Is Still Alive silver trophybronze trophy RetroNetro's Avatar
    Join Date
    Jul 2003
    Location
    Texas
    Posts
    6,883
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hello

    I have been using this, as I could not find anything else that would work:
    Code PHP:
    <?php get_linksbyname('resources', '<li>', '</li>', '', FALSE, 'name', FALSE); ?>
    It says it is deprecated but still works for me.

    http://codex.wordpress.org/Template_...et_linksbyname

    Hope it helps.

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,426
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    cat_ID

    Quote Originally Posted by Johnny Gulag
    It says it is deprecated but still works for me
    AFAIK that function now only takes the args, queries the db to find the cat_ID value using the cat_name arg's value, and then calls get_links()
    In other words, Using get_linksbyname should be the same as using get_links with the same arguments but with cat_ID used instead of cat_name
    I wonder if there's something in a plugin or theme file messing things up?

  7. #7
    SitePoint Guru Marubozo's Avatar
    Join Date
    Mar 2005
    Location
    Near South Bend, Indiana
    Posts
    657
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very interesting, and thanks for all of the suggestions. In regards to plugins, this is a clean install with no plugins currently. I tried putting the number between ' ' and no change.

    I also tried the above with the get_linksbyname function and that did not work either, still displayed nothing. But, interestingly enough if I threw in the category number, not the name in there it would display all links again.

    Even when putting the code in the default WP template it behaves the same. It will either show all of the links or none at all when I specify a category.

    At this point I'm not sure it is worth trying to figure out, there are only 5 links in my total blogroll that I want to segregate to a separate area so it isn't a big deal to just remove them from my blogroll and then hard-code the 5 links.
    Generation X Finance
    Helping a Unique Generation Achieve Financial Independence

    Financial Planning writer at About.com

  8. #8
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,426
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    get linksbyname

    By looking at the get_linksbyname function
    PHP Code:
    .......
    $cat_id = -1;
    $results $wpdb->get_results("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$cat_name'");
        if (
    $results) {
            foreach (
    $results as $result) {
                
    $cat_id $result->cat_ID;
            }
        }
    get_links($cat_id$before$after$between$show_images$orderby$show_description$show_rating$limit$show_updated); 
    If $wpdb->get_results finds a result it returns it, if not it returns NULL. If it returns NULL there is no $result and get_links() uses the default value of -1 (all links).
    Can you look at the db categories table to make sure the cat_name and cat_ID fields are what you expect them to be?

  9. #9
    SitePoint Guru Marubozo's Avatar
    Join Date
    Mar 2005
    Location
    Near South Bend, Indiana
    Posts
    657
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well here is a copy/paste right from the database. cat_ID is 17 and cat_name is what it should be, and it has 6 for link count, which it should.

    Code:
    cat_ID  cat_name  category_nicename  category_description  category_parent  category_count  link_count
    
    17     Personal Finance Network     personal-finance-network           0     0     6
    Generation X Finance
    Helping a Unique Generation Achieve Financial Independence

    Financial Planning writer at About.com

  10. #10
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,426
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    odd bug

    Well, I don't see anything obviously wrong with that. Very strange indeed. If you go the "hard coded" route, I hope you won't have to up scale (add a lot more links) any time soon. But I guess that's what I'd do for now too.

  11. #11
    SitePoint Guru Marubozo's Avatar
    Join Date
    Mar 2005
    Location
    Near South Bend, Indiana
    Posts
    657
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I appreciate all of the effort. It is just one of those oddities that may never be solved, but I just went ahead and added the hard code to my sidebar which only took about 30 seconds and it works fine. I don't plan on having to add/subtract links from this at all so it should be fine.

    Hey, at least I removed a database query from the layout so it might load 0.00001 seconds faster now
    Generation X Finance
    Helping a Unique Generation Achieve Financial Independence

    Financial Planning writer at About.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •