We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7527
    • 437 Posts
    Hi. I currently have a snippet running that works as an A-z search. All is goo but I want to add an ’ALL’ link to show all. And I want to make it default to all when the page is loaded. Here is my snippet

    <?php
    $docid = $modx->documentIdentifier;
    $parents = isset($parents) ? $parents : $docid;
    $dittoTpl = isset($tpl) ? $tpl : "listingtpl"; // ditto tpl to use
    $display = isset($display) ? $display : "20"; // number of items per page to return
    $filterBy = isset($_GET["letter"]) ? strtoupper($_GET["letter"]) : "";
    $filter = "pagetitle,".$filterBy.",11";
    
    //-- Alphabet Letters
    $letter = array (
    	"A",
    	"B",
    	"C",
    	"D",
    	"E",
    	"F",
    	"G",
    	"H",
    	"I",
    	"J",
    	"K",
    	"L",
    	"M",
    	"N",
    	"O",
    	"P",
    	"Q",
    	"R",
    	"S",
    	"T",
    	"U",
    	"V",
    	"W",
    	"X",
    	"Y",
    	"Z"
    );
    
    $table = $modx->getFullTableName("site_content");
    
    foreach($letter as $l){
    	$sql = "SELECT $table.id, $table.pagetitle FROM $table WHERE ( $table.pagetitle LIKE '$l%') AND ($table.parent IN ($parents)) LIMIT 1";
    	$results = $modx->db->query($sql);
    	$count = $modx->db->getRecordCount( $results );
    	if ($count > 0) {
        	$letters .= "<a href=\"[~".$docid."~]&letter=".$l."\">".$l."</a>|";
    	} else {
        	$letters .= $l."|";
    	}
    }
    
    	// get count for pagination
    $v = '';
    if($filterBy != ""){
    	$sql = "SELECT $table.id, $table.pagetitle FROM $table WHERE ( $table.pagetitle LIKE '$filterBy%') AND ($table.parent IN ($parents))";
    	$results = $modx->db->query($sql);
    	$v = $modx->db->getRecordCount( $results );
    }
    // run ditto snippet
    $output = $modx->runSnippet("Ditto", array(
    	"debug" => "0",
    	"parents" => $parents,
    	"depth" => "0",
    	"display" => $display,
    	"paginate" => "1",
    	"paginateAlwaysShowLinks" => "0",
    	"sortBy" => "pagetitle",
    	"sortDir" => "ASC",
    	"tpl" => $dittoTpl,
    	"filter" => $filter,
                         "total" => "all",
                         "extenders" => "glossaryFilter",
                         "hideFolders" => "1",
                         "tplPaginatePage" => "pageSplitter",
                         "tplPaginateCurrentPage" => "currentPageSplitter",
    	"tplPaginatePrevious" => "@CODE <li><a href='[+url+]'>Previous</a></li>\n",
    	"tplPaginateNext" => "@CODE <li><a href='[+url+]'>Next</a></li>\n",
    	"tplPaginateNextOff" => "@CODE <li><a href='[~[*id*]~]#'>Next</a></li>\n",
    	"tplPaginatePreviousOff" => "@CODE <li><a href='[~[*id*]~]#'>Previous</a></li>\n",
    	"tplPaginatePage" => "@CODE <li><a href='[+url+]'>[+page+]</a></li>\n",
    	"tplPaginateCurrentPage" => "@CODE <li class='selected'><a href='[~[*id*]~]#'>[+page+]</a></li>\n" ));
    
    //$pages = "<ul id=\"paging\">
    //[+previous+] 
    //[+pages+] 
    //[+next+]
    //</ul>\n";	
    
    //$v = count($output);
    
    $modx->setPlaceholder('a2zletters', $letters);
    $modx->setPlaceholder('a2z', $output);
    $modx->setPlaceholder('pages', $pages);
    return "<p><strong>".$letters."</strong></p> ".$output.$pages;
    ?>
    

    Any help would be greatly appreciated
      www.PawsForWildlife.co.uk
      www.Borntobrick.co.uk