WordPress.org

Ready to get started?Download WordPress

Forums

breaking up links categories (10 posts)

  1. soccercheese
    Member
    Posted 8 years ago #

    I'm new to WordPress and would like to be able to break the links categories into different positions.

    For example, the blog will have the main navigation links like the main page, but then I'd like to have the blogroll underneath categories and archives?

    Is this possible? Can someone please point me in the right direction?

    I've installed the widgets plugin to help with positioning different parts, but i can uninstall if it would be too much to do it with this plugin.

    I'm not a strong coder, but I have been able to change code in oscommerce and mambo/joomla, so I have a bit of experience.

    Thanks in advance for any help!

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

    Can we have a link to your page?
    If you could then describe precisely what you need then we'll sort the answer :)

  3. soccercheese
    Member
    Posted 8 years ago #

    Podz,

    I'd rather not give out the link because it's far from ready...I hope that's ok. Sorry.

    Is is possible to put structure the sidebar so that categories of links are in different positions?

    For example:
    - Link Category #1
    - Archives
    - Link Category #2 (Blogroll)

    Right now, when I "publish" Links, it puts them all together on the sidebar. I'd just like to be able to break them up or change the order.

  4. Chris_K
    Member
    Posted 8 years ago #

    Does this post help? http://codex.wordpress.org/Template_Tags/get_links_list

    Add sections in your sidebar for each category and make a call to get_links_list() with that categories ID.

  5. soccercheese
    Member
    Posted 8 years ago #

    Yes that helps. Thanks!

    Now...how do I put the <?php get_links_list('id'); ?> as a widget so I can just put them in the order I want?

    I've checked the Widget documentation and I just don't know how... or should I just put it in the sidebar.php page? Or if I put it in the sidebar.php page does it show up in the Widgets on the Admin side?

    Sorry I'm still learning...

  6. moshu
    Member
    Posted 8 years ago #

    If the theme you are using is not prepared for "widgets" that plugin will not work in your theme. (that's when a link is handy to get fast and precise help)

  7. soccercheese
    Member
    Posted 8 years ago #

    yes i understand...sorry didn't mention which theme. I'm just using the default one, Kubrick I think it's called?

    I already have widgets installed and working on the admin side...just wondering if I can make a simple widget that will call just one category of links. then i can make a couple and order them how i want to...

  8. soccercheese
    Member
    Posted 8 years ago #

    ok...i tried to modify widgets.php and sidebar.php

    i put this in sidebar.php (around line 50)

    <?php get_links_list('1'); ?>
    <?php get_links_list('2'); ?>

    i put this in widgets.php (around line 640)

    'function widget_links_1($args)
    {// This ONLY works with li/h2 sidebars.
    get_links_list('1');
    }

    function widget_links_2($args) {
    // This ONLY works with li/h2 sidebars.
    get_links_list('2');
    }<br />

    and

    register_sidebar_widget('Main Nav', 'widget_links_1');
    register_sidebar_widget('Blogroll', 'widget_links_2');`

    at the bottom of the file.

    They showed up as Main Nav and Blogroll in the Widgets on the admin side, and I placed them in the first and third position...but when i view the site it shows both link categories (in reverse order) in both positions...weird.

    Can somebody help me make a widget that will call one link category that will work? what i'm doing isn't working right...

  9. soccercheese
    Member
    Posted 8 years ago #

    any ideas? should I just uninstall the widgets and code it into the sidebar.php?

  10. Rudy64
    Member
    Posted 8 years ago #

    You were on the right track! The problem is that the function get_links_list() does not accept a link category ID number as a parameter.

    What I did was kind of a kludge for now, but it got me going.

    First, in links.php, I created a new function called get_single_links_list() that takes the link ID as a parameter:

    function get_single_links_list($order = 'name', $hide_if_empty = 'obsolete', $linkcategoryid) {
    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
    LEFT JOIN $wpdb->linkcategories ON (link_category = cat_id)
    WHERE link_visible = 'Y'
    AND list_limit <> 0
    AND cat_id = $linkcategoryid
    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="linkcat-' . $cat['link_category'] . '"><h2>' . $cat['cat_name'] . "</h2>\n\t

      \n";
      // Call get_links() with all the appropriate params
      get_links($cat['link_category'],
      '

    • ',"
    • ","\n",
      bool_from_yn($cat['show_images']),
      $orderby,
      bool_from_yn($cat['show_description']),
      bool_from_yn($cat['show_rating']),
      $cat['list_limit'],
      bool_from_yn($cat['show_updated']));

      // Close the last category
      echo "\n\t

    \n\n";
    }
    }
    }

    Next, in widgets.php, around line 650 or so, I added a few blocks of code like this:

    function widget_links_2($args) {
    // This ONLY works with li/h2 sidebars.
    get_single_links_list('name', 'obsolete', 2);
    }

    Notice that in the list of arguments, the "2" is the link category ID number. The modified function above accepts this number and modifies the database query to list only the single category.

    And at the end of widgets.php, I registered the widget:

    register_sidebar_widget('My Links', 'widget_links_2');

    It's working great now!

    What I will do in the near future is modify the original get_links_list() function to take the category ID as an optional third parameter, rather than have the separate function for it. Being in a bit of a rush today, I don't have time to tackle it, but for now I have it working.

    To create the new function, the only changes I made were to add $linkcategoryid as one of the parameters, which is the first line of my new function:

    function get_single_links_list($order = 'name', $hide_if_empty = 'obsolete', $linkcategoryid) {

    Then further down, in the queries, I changed this:

    WHERE link_visible = 'Y'
    AND list_limit <> 0

    by adding this just below it:

    WHERE link_visible = 'Y'
    AND list_limit <> 0
    AND cat_id = $linkcategoryid

    That's it!

    Note that the word wrapping is killing my code here; hopefully my post makes some sense.

Topic Closed

This topic has been closed to new replies.

About this Topic