views:

347

answers:

3

could anybody suggest solution how to display data in treeview like format in wordpress. There is no plugin for that.

I want to display something like table of content. Not talking about pages/categories from wordpress itself.

I found

  • this jQuery plugin that can be used to display my data. I cannot edit and store data using this plugin though.
  • jsTree - a javascript based, cross browser tree component. It is packaged as a jQuery plugin. This looks very promising.

Very important part of the whole solution is how to store the source data of the tree (database or xml ?) and how to update the source data. I found this article very useful.

I am looking for a solution that would let me to display the data and preferably also edit/store them. Editing needs to be available only for admin users.

+1  A: 

You could store data with a left and right property:

12345678901234
-------------- | a
 ------------  | b
  ---- -- --   | c d e
   --          | f

a.left = 1, a.right = 14
b.left = 2, b.right = 13
c.left = 3, c.right = 6
d.left = 8, d.right = 9
e.left = 11, e.right = 12
f.left = 4, f.right = 5

This would give you a tree like:

          a
          |
          b
         /|\
        / | \
       c  d  e
      /
     f

This is a quite tricky solution, but it uses a minimum of queries to select a tree. You can read how to insert, update and delete nodes on mysql.com.

Another simple solution is to give each node a parent property, and start a recursive loop through each of these nodes. This solution is a very expensive one, it uses one query for every node.

Harmen
+1  A: 

Set each node up as a Wordpress page, then use wp_list_pages to output a set of nested <li> elements.

For instance, with the structure

nodes (page id #34)
- category 1
-- subcategory 1
-- subcategory 2
- category 2
-- subcategory 3
-- subcategory 4

Use:

<ul>
<?php wp_list_pages('child_of=34'); ?>
</ul>
adam
@adam: I updated my question.I want to display something like table of content but it is not related to the wordpress application. The data source comes outside wordpress. Setting up each node as a page would be very time consuming as the number could be even hundreds.
Radek
+1  A: 

The simpliest solution is wp_list_pages() it's gonna output you a ul li list of all your page.

if you want to export it as a xml you can make a template page in wordpress that make a xml.

--updated--

@rafik
can you tell me exactly... what you want to do and where.

Because all the link that you put... tell me that we just overkill you're question. :)

Do you just want to display a list like a tree view in a wordpress page?...

If yes the simpliest way to do this is to make a ul li list like this:

<ul id="treeview">
  <li>parent1</li>
  <li>parent2  
    <ul>
      <li>child1 of 2</li>
      <li>child2 of 2</li>
    </ul>
  </li>
</ul>

and in your jquery script:

$(function () { 
  $("#treeview").tree();
});
Eduplessis
@Radek if the data come from outside wordpress it's not a question about wordpress...??
Eduplessis
@Eduplessis: well, in my opinion it is about wordpress too as we have to incorporate the solution within wordpress.Using the links in my questions I could have the solution ready but wordpress makes it all bit more complicated.In my eyes...Maybe because I am not a programmer and do not have experiences with wordpress either.That is why I posted my question here.
Radek
@Radek You have to know that either if it's in wordpress or not it's gonna be a little complicated because you are not a programmer. If you want this outside of wordpress or inside of wordpress it's gonna be the same thing.If you want to update the data: use a database but you gonna have to make a admin page to edit it or edit the database manually... and after if you need your info in any kind of format you can populate it in php http://articles.techrepublic.com.com/5100-10878_11-5035149.html
Eduplessis
@Eduplessis: I don't think that it is the same outsite or within wordpress. There is lots of tutorials how to do things outside wordpress but I haven't found any how to do something similar within. Thank you for the link, I'll have a look.
Radek
http://www.jstree.com/ looks promising ....
Radek
I have updated my answer
Eduplessis
@Eduplessis: thank you for the update. To display the data in treeview I can use the jQuery but I am also looking how to store the data and how to edit them
Radek