Hi !

I need some help of a PHP coder to write a code that will display in a block the related flexinodes to the current one by taxonomy term and with the ability to choose which fields of the custom content type are displayed

On the website I've created, I've made a flexinode for discs chronicles whith many fields such as "name of the artist", "cover of the disc" etc. Each music style has its own subterm after the main term "discs"

So, when the current node belongs to the subterm "jazz" for e.g. I'd like to display in a block all the covers of the discs that belongs to this category with link to the full node.

I've found a code to display the "related nodes by term" which may be modified and I have a code to "display the last (x) flexinodes with custom layout".

The first one is...

<?php
if (arg(0) == 'node' && is_numeric(arg(1)) && is_null(arg(2))) {
  $nid = (int)arg(1);
  $terms = taxonomy_node_get_terms($nid);
  $output = "<ul>";
  foreach($terms as $term){
    $sql = "SELECT n.title, n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid = $term->tid AND n.nid != $nid LIMIT 5";   
    $result = db_query(db_rewrite_sql($sql));
    if (db_num_rows($result)) {
      $output .="<li>$term->name</li><ul>";
      while ($anode = db_fetch_object($result)) {
        $output .= "<li>".l($anode->title, "node/$anode->nid")."</li>";
      }   
      $output.="</ul>";
    }
  }
  $output .= "</ul>";
  return $output;
}
?>

The second one is...

<?php
$flexi_id = "flexinode-1";
$list_no =8;
$sql = "SELECT node.type, node.nid FROM node WHERE node.type = '$flexi_id' ORDER BY created DESC LIMIT $list_no";
$result = db_query($sql);
while ($node = db_fetch_object($result)) {
  $nid = $node->nid;
//    print node_view(node_load(array('nid' => $node->nid)), 1);
  $data = node_load($nid);
?>

<a href="node/<?php print $data->nid ?>"><img src="<?php print file_create_url($data->flexinode_6->thumbpath) ?>" title="<?php print $data->flexinode_1 ?> :: <?php print $data->flexinode_3 ?>" /></a>
<?php
}
?>

I think a mix of them can be done to display in a block the related flexinodes to the current one by taxonomy term and with the ability to choose which fields of the custom content type are displayed but I need the help of a php "guru" to do it because I don't know PHP...

I hope you can help me ! :D

Thank you ;)

Comments

Anonymous’s picture

I forgot to say that it would be cool if the block was shown only if there are other nodes in this category... :)

Anonymous’s picture

No answers ? :)

Squidgy’s picture

You might want to look at the Views module as an alternative. Changing the mysql query so that it selects only from that term and, say, the 5 most recent nodes is quite easy, but making it so that the end-user can quickly select what field to sort by is another matter entirely. Flexinode's not as flexible as it might be in that way - CCK might be simpler in some ways, loath as I am to admit it.

Anonymous’s picture

I looked at CCK and I didn't understood how it works :)
For me flexinode seems to be much simple to use and to layout...

Anyway, that's an idea, I'll study this solution if nobody can help me with the code ;)

Thank you

Anonymous’s picture

I've modified my site to use CCK even if the image cropping and resize is absolutely awfull...
Now, I have the same problem because this "view" module seems to be very complicated to manage. I just want to display 8 thumbnails from the last 8 nodes in the current category. Then I want to display these thumbnails in a block. How can I do that with the "View" module ?

Thank you ;)

Squidgy’s picture

I understand your frustration, man, but deleting and reposting the same comment isn't going to help. Have you tried looking at the Views documentation? Also, try connecting to the irc support chat line and talk to people who would be more familiar with views.

Anonymous’s picture

I've not deleted the comment, I've just made some modifications to make it clearer... :)
Well, Yes I've tried to read the documentation and I don't understand clearly how this module can help me doing what I want. I'll try the IRC. I didn't know there was one. Thank you ;)

Anonymous’s picture

Maybe I've found the solution even for now it doesn't work but when yuo say "changing the mysql query" to have the current term nodes only. Do you know how to do it ?

Thank you.