We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29076
    • 615 Posts
    Hmm, how should I make this understandable? I’ll try:

    I have some (species)documents with pagetitles like Draba oxycarpa, Draba corymbosa, Draba fladnizensis etc. Or Saxifraga oppositifolia, Saxifraga cespitosa etc. (That is Genus species). And I have a snippet called getGenusName with the code
    <?php
    $text = $modx->documentObject['pagetitle'];
    $string = strip_tags($text); 
    $t =explode (' ',$string);
    echo $t[0];
    ?>

    This way I return Draba or Saxifraga or whatever the first part of the pagetitle from the pagetitle. So far so good.

    Next, I have a container with ID=707 that contains documents. One of the documents have the pagetitle Draba, another Saxifraga. The respective content of this documents have a text (the meaning of the name Draba or the name Saxifraga etc.)

    tongue Problem: What I want is a Ditto-call in the template for the first group of documents (like Draba corymbosa or Saxifraga oppositifolia etc.) that takes the first part of in example Draba corymbosa, that would be Draba, and compare it with the pagetitles in container ID=707. When there is a match, like Draba matches Draba, or Saxifraga matches Saxifraga or whatever the name, then display the content-text in the container ID=707/document pagetitle=the matching name in the template for all the species-documents. The meaning of the name Draba will be displayed on all the Draba xxxx pages, and the meaning of the name Saxifraga will be displayed on all the Saxifraga xxxx pages.

    This way, I’ll have the meening of the Genus-name displayed in all the Species-pages. Take a look at svalbardflora.net for examples (it’s a non-commersial site, and I do not collect hits).

    Thanks. smiley
      I think, thererfor I am! But what I am, and why...?
      • 10449
      • 956 Posts
      This would have been a lot easier and straightforward if you had just inserted a "genus" TV (widget = checkbox or radio buttons), e.g.
      document "Draba corymbosa" -> the checkbox "Draba" would be checked.
      The TV would just generate a list of all the docs in container 707, based on the pagetitle.
        • 10449
        • 956 Posts
        Try this:

        <?php
        $text = $modx->documentObject['pagetitle'];
        $string = strip_tags($text);
        $t = explode (' ',$string);
        $genus = $t[0];
        
        $table = $modx->getFullTableName("site_content");
        $dbQuery = " SELECT id, content FROM $table WHERE pagetitle='$genus' LIMIT 0,1";
        $result = mysql_query($dbQuery) or die( mysql_error() );
        if(mysql_num_rows($result) > 0) {
        	while ($row = mysql_fetch_array($result)) {
        		extract($row);
        	}
        	// this would create a link to the page:
        	$genusURL = $modx->makeUrl($id);
        
        	// actual content:
        	$genusContent = $content;
        	return($genusContent);
        }
        ?>
        


        Don’t have time to test it, but it should work.
          • 29076
          • 615 Posts
          Some (many) of you people here in the MODx forums are just incredible helpful. This solution works perfect. Thank you very much! laugh
            I think, thererfor I am! But what I am, and why...?
            • 29076
            • 615 Posts
            Is there a way to tell ganeshXL’ script to only search in container ID=707?  tongue  smiley The way it’s now it goes through all the documents.
              I think, thererfor I am! But what I am, and why...?
              • 10449
              • 956 Posts
              Try this:

              SELECT id, content FROM $table WHERE pagetitle='$genus' AND parent=707 LIMIT 0,1
              


                • 7231
                • 4,205 Posts
                Need to be pretty fast to answer a post around here... rolleyes This is what I would have said if GaneshXL did not beet me to it grin

                Sure, just add the parent=707 to the query:

                $dbQuery = " SELECT id, content FROM $table WHERE pagetitle='$genus' AND parent=707 LIMIT 0,1";

                I will type faster next time grin
                  [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                  Something is happening here, but you don&#39;t know what it is.
                  Do you, Mr. Jones? - [bob dylan]
                  • 10449
                  • 956 Posts
                  grin
                    • 29076
                    • 615 Posts
                    "The man who types faster than his own shadow!"

                    Thanks, I thought it was something like this. laugh
                      I think, thererfor I am! But what I am, and why...?