mod_dropdownarticles Sortierung ändern
- sapo12
-
Autor
- Offline
- Junior Mitglied
-
Weniger
Mehr
27 Aug. 2011 12:59 #31291
von sapo12
mod_dropdownarticles Sortierung ändern wurde erstellt von sapo12
ich habe das Modul mod_dropdownarticles
extensions.joomla.org/extensions/news-di...rticles-listing/7102
installiert und möchte die Sortierung von Title nach Datum ändern.
Habe lange gegoogelt, finde aber nur Fragen, aber keine Antwort.
Dies ist das Original php
ich dachte, ich könnte es selber ersetzen, leider fehlt mir das Wissen dazu. Dies habe ich probiert.
Was mach ich falsch?
Danke für die Hilfe
installiert und möchte die Sortierung von Title nach Datum ändern.
Habe lange gegoogelt, finde aber nur Fragen, aber keine Antwort.
Dies ist das Original php
Code:
<?php
/**
* Joomla Drop Down Articles
* @package Drop Down Articles
* @version 1.5.2
* @subpackage mod_dropdownarticles.php
* @revision $Revision: 1.2 $
* @author Andrea Forghieri
* @copyright (C) Andrea Forghieri, www.solidsystem.it
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU/GPL version 2
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
global $Itemid, $mainframe;
$database = & JFactory :: getDBO();
$user = & JFactory :: getUser();
$moduleclass_sfx = $params->def('moduleclass_sfx', '');
$title_field = $params->def('title_field', '0');
$select_text = $params->def('select_text', 'Go to article...');
$use_local_css = $params->def('use_local_css', '1');
$sections = preg_replace('/[^0-9\,]|\,$/', '', $params->def('sections', ''));
$categories = preg_replace('/[^0-9\,]|\,$/', '', $params->def('categories', ''));
$opt_max_chars = preg_replace('/[^0-9]/', '', $params->def('opt_max_chars', ''));
$select_width = preg_replace('/[^0-9]/', '', $params->def('select_width', ''));
$option_width = preg_replace('/[^0-9]/', '', $params->def('option_width', ''));
$use_itemid = preg_replace('/[^0-9]/', '', $params->def('use_itemid', ''));
$force_itemid = preg_replace('/[^0-9]/', '', $params->def('force_itemid', ''));
switch($use_itemid){
case 1 :
$thisItemid = "<input type=\"hidden\" name=\"Itemid\" value=\"$Itemid\"/>";
break;
case 2:
if($force_itemid > 0 ) $thisItemid = "<input type=\"hidden\" name=\"Itemid\" value=\"$force_itemid\"/>";
break;
default:
$thisItemid = "";
}
$contentConfig = & JComponentHelper :: getParams('com_content');
$access = !$contentConfig->get('shownoauth');
$gid = $user->get('gid');
$jnow =& JFactory::getDate();
$now = $jnow->toMySQL();
$nullDate = $database->getNullDate();
$got_JoomFish = file_exists($mainframe->getCfg('absolute_path') . '/administrator/components/com_joomfish/joomfish.php') ? true : false;
$query = "SELECT c.id AS id, c.title AS title, c.alias as title_alias
FROM #__content AS c
INNER JOIN #__categories AS cat
ON(c.catid = cat.id) AND (cat.access <= $gid)
INNER JOIN #__sections AS sec
ON(c.sectionid = sec.id)
WHERE c.state = '1'
AND ( c.publish_up = " . $database->Quote($nullDate) . " OR c.publish_up <= " . $database->Quote($now) . " )
AND ( c.publish_down = " . $database->Quote($nullDate) . " OR c.publish_down >= " . $database->Quote($now) . " )
AND cat.published = '1'
AND sec.published = '1' ";
if ($access) {
$query .= " AND c.access <= $gid \n";
}
if ($sections != '') {
$query .= "AND sec.id in ($sections) \n";
}
if ($categories != '') {
$query .= "AND cat.id in ($categories) \n";
}
if (!$got_JoomFish) {
if ($title_field == 0) {
$query .= "ORDER BY c.title";
} else {
$query .= "ORDER BY c.alias";
}
}
$database->setQuery($query);
$rows = $database->loadObjectList();
if ($got_JoomFish) {
if ($title_field == 0) {
sortArrayObjects($rows, 'title');
} else {
sortArrayObjects($rows, 'title_alias');
}
}
$sel_style = "";
$opt_style = "";
if ($use_local_css) {
$sel_style = $select_width != "" ? "style=\"width: " . $select_width . "px\"" : "";
$opt_style = $option_width != "" ? "style=\"width: " . $option_width . "px;\"" : "";
}
if ($rows) {
?>
<div class="dda<?php echo $moduleclass_sfx?>" >
<form method="get" action="index.php" name="ddaForm">
<input type="hidden" name="option" value="com_content"/>
<input type="hidden" name="view" value="article"/>
<?php echo $thisItemid; ?>
<select name="id" onchange="this.form.submit();" class="inputbox" <?php echo "$sel_style" ?>>
<?php
if ($select_text != "off") {
echo "<option $opt_style value=\"\">".htmlspecialchars($select_text)."</option>";
}
foreach ($rows as $row) {
if ($title_field == '1') {
$title = $row->title_alias;
} else {
$title = $row->title;
}
$title = $opt_max_chars > 0 && strlen($title) > $opt_max_chars ? substr($title, 0, $opt_max_chars) . '...' : $title;
echo "<option $opt_style value=\"" . $row->id .":". $row->title_alias ."\">". htmlspecialchars($title) . "</option>\n";
}
?>
</select>
</form>
</div>
<?php
} else {
?>
<div class="dda<?php echo $moduleclass_sfx?>" >
No articles to show.
</div>
<?php
}
?>
Code:
<?php
/**
* Joomla Drop Down Articles
* @package Drop Down Articles
* @version 1.5.2
* @subpackage mod_dropdownarticles.php
* @revision $Revision: 1.2 $
* @author Andrea Forghieri
* @copyright (C) Andrea Forghieri, www.solidsystem.it
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU/GPL version 2
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
global $Itemid, $mainframe;
$database = & JFactory :: getDBO();
$user = & JFactory :: getUser();
$moduleclass_sfx = $params->def('moduleclass_sfx', '');
$title_field = $params->def('title_field', '0');
$select_text = $params->def('select_text', 'Go to article...');
$use_local_css = $params->def('use_local_css', '1');
$sections = preg_replace('/[^0-9\,]|\,$/', '', $params->def('sections', ''));
$categories = preg_replace('/[^0-9\,]|\,$/', '', $params->def('categories', ''));
$opt_max_chars = preg_replace('/[^0-9]/', '', $params->def('opt_max_chars', ''));
$select_width = preg_replace('/[^0-9]/', '', $params->def('select_width', ''));
$option_width = preg_replace('/[^0-9]/', '', $params->def('option_width', ''));
$use_itemid = preg_replace('/[^0-9]/', '', $params->def('use_itemid', ''));
$force_itemid = preg_replace('/[^0-9]/', '', $params->def('force_itemid', ''));
switch($use_itemid){
case 1 :
$thisItemid = "<input type=\"hidden\" name=\"Itemid\" value=\"$Itemid\"/>";
break;
case 2:
if($force_itemid > 0 ) $thisItemid = "<input type=\"hidden\" name=\"Itemid\" value=\"$force_itemid\"/>";
break;
default:
$thisItemid = "";
}
$contentConfig = & JComponentHelper :: getParams('com_content');
$access = !$contentConfig->get('shownoauth');
$gid = $user->get('gid');
$jnow =& JFactory::getDate();
$now = $jnow->toMySQL();
$nullDate = $database->getNullDate();
$got_JoomFish = file_exists($mainframe->getCfg('absolute_path') . '/administrator/components/com_joomfish/joomfish.php') ? true : false;
$query = "SELECT c.id AS id, c.title AS title, c.alias as title_alias, c.date as date
FROM #__content AS c
INNER JOIN #__categories AS cat
ON(c.catid = cat.id) AND (cat.access <= $gid)
INNER JOIN #__sections AS sec
ON(c.sectionid = sec.id)
WHERE c.state = '1'
AND ( c.publish_up = " . $database->Quote($nullDate) . " OR c.publish_up <= " . $database->Quote($now) . " )
AND ( c.publish_down = " . $database->Quote($nullDate) . " OR c.publish_down >= " . $database->Quote($now) . " )
AND cat.published = '1'
AND sec.published = '1' ";
if ($access) {
$query .= " AND c.access <= $gid \n";
}
if ($sections != '') {
$query .= "AND sec.id in ($sections) \n";
}
if ($categories != '') {
$query .= "AND cat.id in ($categories) \n";
}
if (!$got_JoomFish) {
if ($title_field == 0) {
$query .= "ORDER BY c.date";
} else {
$query .= "ORDER BY c.title";
}
}
$database->setQuery($query);
$rows = $database->loadObjectList();
if ($got_JoomFish) {
if ($title_field == 0) {
sortArrayObjects($rows, 'date');
} else {
sortArrayObjects($rows, 'title');
}
}
$sel_style = "";
$opt_style = "";
if ($use_local_css) {
$sel_style = $select_width != "" ? "style=\"width: " . $select_width . "px\"" : "";
$opt_style = $option_width != "" ? "style=\"width: " . $option_width . "px;\"" : "";
}
if ($rows) {
?>
<div class="dda<?php echo $moduleclass_sfx?>" >
<form method="get" action="index.php" name="ddaForm">
<input type="hidden" name="option" value="com_content"/>
<input type="hidden" name="view" value="article"/>
<?php echo $thisItemid; ?>
<select name="id" onchange="this.form.submit();" class="inputbox" <?php echo "$sel_style" ?>>
<?php
if ($select_text != "off") {
echo "<option $opt_style value=\"\">".htmlspecialchars($select_text)."</option>";
}
foreach ($rows as $row) {
if ($title_field == '1') {
$title = $row->title_alias;
} else {
$title = $row->title;
}
$title = $opt_max_chars > 0 && strlen($title) > $opt_max_chars ? substr($title, 0, $opt_max_chars) . '...' : $title;
echo "<option $opt_style value=\"" . $row->id .":". $row->title_alias ."\">". htmlspecialchars($title) . "</option>\n";
}
?>
</select>
</form>
</div>
<?php
} else {
?>
<div class="dda<?php echo $moduleclass_sfx?>" >
No articles to show.
</div>
<?php
}
?>
Danke für die Hilfe
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
- Tribal6
-
- Offline
-
06 Sep. 2011 21:38 #31641
von Tribal6
Tue das, was du kannst, mit dem was du hast, da wo du bist.
Tribal6 antwortete auf Aw: mod_dropdownarticles Sortierung ändern
Hi
Ich denke mal, auf dem richtigen Weg bist du. Du willst da aber aus der Content-Tabelle zusätzlich noch die Tabellenspalte 'date' auslesen (c.date as date). Die gibt es aber nicht. Nimm anstelle davon mal 'created', also (c.created as date).
Und bei der (überigens 'deprecated') function sortArrayObjects(), wäre ich mir nicht so sicher, ob die mit dem Datum-Typ zurecht kommt, rsp. so funktioniert, wie sie sollte.
Die braucht's ja eigentlich eh nicht, du kannst ja schon in der Query nach 'neuestes Datum zuerst' sortieren (korrekt wäre 'ORDER BY c.date DESC' = absteigend = aktuellstes zuerst).
Und wenn du die nachträglich geänderten Beiträge auch noch mit berücksichtigen willst (geändert = wieder neu und aktuell), dann kannst du eine Abfrage in die Query einbauen, welches Datum neuer ist: 'created' oder 'modified'. Das ginge dann ungefähr so:
Ein Limit in der Query (oder im Code) wäre ev. auch nicht schlecht, damit die Liste nicht zu lange wird (z.B. nur die 10 neusten Beiträge).
Cheers
Roger
Ich denke mal, auf dem richtigen Weg bist du. Du willst da aber aus der Content-Tabelle zusätzlich noch die Tabellenspalte 'date' auslesen (c.date as date). Die gibt es aber nicht. Nimm anstelle davon mal 'created', also (c.created as date).
Und bei der (überigens 'deprecated') function sortArrayObjects(), wäre ich mir nicht so sicher, ob die mit dem Datum-Typ zurecht kommt, rsp. so funktioniert, wie sie sollte.
Die braucht's ja eigentlich eh nicht, du kannst ja schon in der Query nach 'neuestes Datum zuerst' sortieren (korrekt wäre 'ORDER BY c.date DESC' = absteigend = aktuellstes zuerst).
Und wenn du die nachträglich geänderten Beiträge auch noch mit berücksichtigen willst (geändert = wieder neu und aktuell), dann kannst du eine Abfrage in die Query einbauen, welches Datum neuer ist: 'created' oder 'modified'. Das ginge dann ungefähr so:
Code:
SELECT c.id AS id,
c.title AS title,
c.alias as title_alias,
CASE WHEN c.modified < c.created THEN c.created ELSE c.modified END as date
FROM #__content AS c
.......
Ein Limit in der Query (oder im Code) wäre ev. auch nicht schlecht, damit die Liste nicht zu lange wird (z.B. nur die 10 neusten Beiträge).
Cheers
Roger
Tue das, was du kannst, mit dem was du hast, da wo du bist.
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
Moderatoren: Tribal6, RePao, Dragonlord, Chris Hoefliger, pascale, adiheutschi.ch