We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15066
    • 27 Posts
    Hello!

    I hope i am writeing at a righ place...

    I have a problem with ditto news. On Home page, i would like to have only news, which will get unpublished today.
    Is there a way to call it?

    Thank you for your help, Jure
      • 7231
      • 4,205 Posts
      You may be able to get this done with the datefilter extension, or you can build a wrapper snippet that does a query to find the desired documents and then use this to output Ditto. I did this recently to get the documents that were to be published today, so it could be adapted to get documents to be unpublished. Se the code in this post:
      http://modxcms.com/forums/index.php/topic,16012.msg185112.html#msg185112
        [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't know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 15066
        • 27 Posts
        Thank you... i’ll try it wink
          • 7231
          • 4,205 Posts
          It should work, just change pub_date to unpub_date and increase the limit from 1 (I only needed 1 document) then you will ned to loop through the results to get an array of docs to use as the &documents parameter in Ditto.
            [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't know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 15066
            • 27 Posts
            Hello again...

            It works for one document, but now i need to create it for more documents... like you said...
            I’we tried with "while loop" ... but no luck sad

            Could you please help me whit idea how can i do it ?

            Thank you for your help, Jure
              • 7231
              • 4,205 Posts
              Change the part that returns the data and add the while loop (note I added the php tags to add the color syntax):
              <?php
              if($modx->db->getRecordCount($rs) >= 1) {
              	$row = $modx->db->getRow($rs);
              	// go trough the results and build the document list
              	while( $row = $modx->db->getRow( $rs ) ) {
              		$today_doc .= $row['id'].",";
              		}
              	// remove the extra comma	
              	$today_doc = substr($today_doc, 0, -1);	
              } else {
              	$today_doc = $default;
              }?>
              Basically we are adding the while loop and then running the substr to remove the last comma in the list. I did not test this but it should work.
                [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]
                • 15066
                • 27 Posts
                Hello! I still have problem... now i don’t get any results...

                Here is your code... if you would please check it out.

                <?php
                $parent = isset($parent) ? $parent : "0";
                $default = isset($default) ? $default : "1";
                
                $table = $modx->getFullTableName("site_content");
                $fields = "id";
                $where = "(FROM_UNIXTIME( unpub_date, '%Y-%m-%d' ) = CURDATE( )) AND (parent = ".$parent.") AND (published = '1')";
                $rs = $modx->db->select("id",$table,$where,"unpub_date DESC","5");
                if($modx->db->getRecordCount($rs) >= 1) {
                	$row = $modx->db->getRow($rs);
                	while( $row = $modx->db->getRow( $rs ) ) {
                		$today_doc .= $row['id'].",";
                		}
                	$today_doc = substr($today_doc, 0, -1);	
                } else {
                	$today_doc = $default;
                
                $output = $modx->runSnippet("Ditto_dogodki", array(
                	"documents" => $today_doc,
                	"display" => $display,
                	"tpl" => "ditto-prva" ));
                
                return $output;
                ?>


                Thank you for your help, Jure
                  • 7231
                  • 4,205 Posts
                  You are missing a  } to close the else statement so the snippet never gets executed.

                  <?php
                  $parent = isset($parent) ? $parent : "0";
                  $default = isset($default) ? $default : "1";
                  
                  $table = $modx->getFullTableName("site_content");
                  $fields = "id";
                  $where = "(FROM_UNIXTIME( unpub_date, '%Y-%m-%d' ) = CURDATE( )) AND (parent = ".$parent.") AND (published = '1')";
                  $rs = $modx->db->select("id",$table,$where,"unpub_date DESC","5");
                  if($modx->db->getRecordCount($rs) >= 1) {
                  	while( $row = $modx->db->getRow( $rs ) ) {
                  		$today_doc .= $row['id'].",";
                  		}
                  	$today_doc = substr($today_doc, 0, -1);	
                  } else {
                  	$today_doc = $default;
                  } // <= THIS IS THE MISSING BRACKET
                  
                  $output = $modx->runSnippet("Ditto_dogodki", array(
                  	"documents" => $today_doc,
                  	"display" => $display,
                  	"tpl" => "ditto-prva" ));
                  
                  return $output;
                  ?>
                    [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]
                    • 15066
                    • 27 Posts
                    Hello!

                    Sorry for delay smiley ... it works fine, but i have another problem. It echos out max. 3 docs... and i have nowhere limit to 3...

                    Any other idea?

                    Thank you very much for your time.

                    Jure
                      • 7231
                      • 4,205 Posts
                      My mistake, 3 is the default limit for ditto. The problem is that the $display var is not set. Change this line: "display" => $display, in the ditto params array to "display" => "all",

                      OR

                      define the display var by adding $display = "all"; to the start after the $default is set.

                        [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]