SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast antitoxic's Avatar
    Join Date
    Apr 2008
    Location
    London, UK
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Drupal: List of used tags in category X

    Ola,
    I'm setting up Drupal CMS. In many other CMSs you may extact a list from the top tags in given category or to generate tag cloud for certain category.
    I've already set up all the rest modules and settings.
    I can't get this list.
    I'm using 1 vocabulary for categories and 1 for tags.
    Through "Views" module I am able to make a list for the overall top tags. But there is no filter or relationshop to add between a term from tags and term from categories.

    Any ideas?

  2. #2
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think I fully understand your issue. Do you want a tag cloud containing the most popular tags from both vocabularies?

  3. #3
    SitePoint Enthusiast antitoxic's Avatar
    Join Date
    Apr 2008
    Location
    London, UK
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No Greg,

    I have two vocabularies. One is for categories, one for tags.

    I now gave up hope for a plugin or view from Views and I will use that:
    Code:
    SELECT term_data.tid AS term_id, term_data.name AS term_name
    FROM term_data
    LEFT JOIN term_node AS article_ids ON article_ids.tid =5
    LEFT JOIN term_node AS article_termids ON article_termids.nid = article_ids.nid
    WHERE term_data.tid = article_termids.tid
    GROUP BY term_id
    ORDER BY term_data.weight
    LIMIT 0 , 10
    To get all termed that tagged nodes from category with id 5 .
    Then just use l() and markup around to build a list .

    If any better suggestions please do slam me with your hummer of truth [:

  4. #4
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, nothing springs to mind without searching through the various Views extension modules available. It's often smarter to build a module which extends Views to achieve what you want - the API of the Views module *should* make the code more manageable, but there's a learning curve there and it might take you longer.

    Have you tried asking in the IRC channel? Sometimes someone might be able to help.

  5. #5
    SitePoint Enthusiast antitoxic's Avatar
    Join Date
    Apr 2008
    Location
    London, UK
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well as I chose CMS it was to make "living" site quicker.
    So I would make 1 little function to get me the results . Formatting and outputting [:


    But I don't know where to execute the fucntion and when? Currently I have it into the template which doesn't look pretty.

  6. #6
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It certainly shouldn't be in the template!

    You should create your own module really. But it's not really possible to do Drupal teaching in a bulletin board thread.

    Look in to making your own module, hook_menu, hook_block and the theme() function (Drupal theming layer). The Drupal API is tough to learn but the rewards are worth the pain.

  7. #7
    SitePoint Enthusiast antitoxic's Avatar
    Join Date
    Apr 2008
    Location
    London, UK
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Will have a look. I love the api search system and reference so I hope it wouldn't be that hard to make me be eternally drunk on Guinness [:

  8. #8
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright, here's how it should be:

    You should create a module (must have a .module file containing your code and a .info file - copy from another module and modify).

    Hooks in Drupal work like this - they allow you to "hook" in to bits of Drupal's functionality. For example, confusingly, hook_menu allows you to create pages (and menu items). hook_block is for creating blocks, etc. You invoke hooks by naming them according to your .module file name, e.g. if your module is mymodule.module then your hooks will be invoked by replacing 'hook_' with 'mymodule_'. The easiest way to learn a hook is copy it from another module and/or read the documentation at api.drupal.org - sometimes it's very good, sometimes it isn't.

    So, if you had a module called mymodule.module and with an info file of mymodule.info, I would achieve what you want with four functions:

    - mymodule_menu() - implementation of hook_menu()
    - mymodule_block() - implementation of hook_block()
    - mymodule_build_terms() - your own function for building your results
    - theme_mymodule_list_terms() - the theme function, defining how your results should be rendered

    mymodule_menu() would be dynamic and call mymodule_build_terms() for the content - I would pass elements of the URL using the Drupal arg() function as 'callback arguments' to make the page respond to different term IDs in the URL.

    mymodule_block() would expose the same data in a block and be nearly identical to your hook_menu() implementation, so you can use your data in a block if you wish, which might be useful.

    mymodule_build_terms() would be the actual logic function, containing your SQL and returning a themed array of terms and all data you require for your output, e.g. the return line would look like this, where $data is an array of node ids, titles, etc.

    PHP Code:
    return theme('mymodule_list_terms'$data); 
    The theme function will automatically call theme_mymodule_list_terms() which should return a string of valid HTML having used the l() function (or perhaps a core theme function like the item list) based on the $data array which was passed to it. We do this so other developers can alter the output of our module without hacking our core code. You need to read up on the theme() function to understand.

    I hope that helps! Now, I really need to go to bed.

  9. #9
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ps - if I've confused your requirements in my example, apologies, but I hope the *principle* is clear regardless.


Tags for this Thread

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
  •