Home › Forums › Games discussies › categorieen weergeven
- Dit onderwerp bevat 4 reacties, 2 deelnemers, en is laatst geüpdatet op 15 jaren, 6 maanden geleden door Yorick.
- AuteurBerichten
- 06/11/2008 17:59 om 17:59 #119030
Ik ben een beetje aan het prutsen aan een nieuwe site en zit met volgend probleem: Ik zou graag achter mijn artikelen bij recent nieuws de categorie weergeven waarin ze zitten. Nu heb ik al vanalles aan het proberen geweest maar ik kom er niet uit… Ik kom nu voorlopig tot onderstaand resultaat: (Enkel bovenste artikel zit in categorie ‘neobux’, rest in ‘bux.to’)
[img]http://img393.imageshack.us/img393/9241/probleemdutchbuxsy1.th.jpg[/img] [img]http://img393.imageshack.us/images/thpix.gif[/img] hieronder staat de code die achter recent nieuws zit.
Code:get( ‘source’, 2 ); //default to category
// id value corresponding to selected items/cats/section
$id = trim( $params->get( ‘id’ ) );
$id = rtrim($id,”,”); //strip trailing comma, if any
// number of items to display
$number = trim( $params->get( ‘items’, 5 ) ); //default to five items
//type of link list: 1=plain; 2= bulleted; 3= numbered
$type = $params->get( ‘list_type’, 2 ); //default to bulleted
//order of link list: created, title, id
$order = $params->get( ‘list_order’, ‘created’ ); //default to created
//sort order of link list: asc; desc
$sort = $params->get( ‘list_sort’, ‘desc’ ); //default to descending
//Show date below title link?
$show_date = $params->get( ‘show_date’, ‘no’ ); //default to no date
//Format of list date?
$date_format = $params->get( ‘date_format’, ‘%Y/%m/%d’ ); //default to year/month/day
//enable mouseover overlib tooltip?
$enable_tooltip = $params->get( ‘enable_tooltip’, ‘no’ ); //default to no tooltip
/*Content Link Mouseover Fields */
//fields to show in overlib tooltip
$tooltip_intro = $params->get( ‘tooltip_intro’, ‘no’ ); //default to no
$tooltip_intro_word_count = $params->get( ‘tooltip_intro_word_count’ );
if(!$tooltip_intro_word_count && $tooltip_intro_word_count != 0){
$tooltip_intro_word_count = ’25’; //default to 25 words
}
$tooltip_created = $params->get( ‘tooltip_created’, ‘no’ ); //default to no
$tooltip_created_date_format = $params->get( ‘tooltip_created_date_format’, ‘%Y/%m/%d’ ); //default to year/month/day
$tooltip_author = $params->get( ‘tooltip_author’, ‘no’ ); //default to no
//tooltip styles
$tooltip_bgcolor = $params->get( ‘tooltip_bgcolor’, ‘#24537d’ ); //default to dark blue
$tooltip_fgcolor = $params->get( ‘tooltip_fgcolor’, ‘#E1F0FF’ ); //default to light blue
$tooltip_border = $params->get( ‘tooltip_border’, ‘1’ ); //default to 1px border
$tooltip_capcolor = $params->get( ‘tooltip_capcolor’, ‘#ffffff’ ); //default to white
$tooltip_textcolor = $params->get( ‘tooltip_textcolor’, ‘#000000’ ); //default to black
$tooltip_images = $params->get( ‘tooltip_images’, ‘1’ ); //default to true
//extra tooltip parameters
$tooltip_extra_invocation_string = $params->get( ‘tooltip_extra_invocation_string’ );
if(!$tooltip_extra_invocation_string){
$tooltip_extra_invocation_string = “”; //default
}
else{
$tooltip_extra_invocation_string = “,”.$tooltip_extra_invocation_string;
}
//checking if function exists first allows multiple copies of module on page and avoids redeclaration error
if(!function_exists(”getContentItems”)){
//Get Content Function
function getContentItems($source, $id, $number, $order, $sort, $date_format, $tooltip_intro){
//returns selected content items as associative array
global $mainframe, $database, $my;
switch($source){
//check type of content item to return, set where clause. Allows for multiple categories, sections, items
case ‘1’: //content item
$where = “id IN ($id)”;
break;
case ‘2’: //category
$where = “catid IN ($id)”;
break;
case ‘3’: //section
$where = “sectionid IN ($id)”;
break;
}
$nullDate = $database->getNullDate(); //used for published check
$now = _CURRENT_SERVER_TIME; //ditto
$content = array(); //stores content items
if($tooltip_intro==’yes’){ $introtext = ‘, introtext ‘;}else{$introtext=””;} //get introtext only if requested
//Select query checks whether item is published, is not checked out and whether user has permission to access item
$query=”SELECT id, title, created, created_by”.$introtext.” FROM #__content WHERE ($where)” //has specified id(s)
. ” AND ( ‘$now’ <= publish_down OR publish_down = '$nullDate' AND state = 1 )" //still up and published . " AND ( '$now' >= publish_up OR publish_up = ‘$nullDate’)” //publishing period is active
. ” AND ( checked_out = 0 OR checked_out = $my->id )” //not checked out or checked out by me
. ” AND (access <= $my->gid)” //permission to access
. ” ORDER BY $order $sort”
. ” LIMIT $number”; //limit number of items to return
//query the DB
$database->setQuery($query);
$database->query();
//load items into object array
$content_list=$database->loadObjectList();
$total=count($content_list);
//loop through and generate the array of content item links
for($i=0;$i<$total;$i++){ //print $mainframe->getItemid($content_list[$i]->id);
$link=”index.php?option=com_content&task=view&id=”.$content_list[$i]->id.”&Itemid=”.$mainframe->getItemid($content_list[$i]->id);
$content[$i][’id’]=$content_list[$i]->id;
$content[$i][’title’]=$content_list[$i]->title;
$content[$i][’author’]=$content_list[$i]->created_by;
if($introtext){$content[$i][’introtext’]=$content_list[$i]->introtext;}
$content[$i][’date’]=mosFormatDate($content_list[$i]->created, $date_format);
$content[$i][’link’]=sefRelToAbs($link); //search engine friendly URL, if SEF is off normal URL is displayed
}
return $content;
}
}
if(!function_exists(”getIntroText”)){
//returns introtext chunk
function getIntroText($text, $length, $tooltip_images){
$text = str_replace(”{mosimage}”,””,$text); //strip out mosimage tags
$text = preg_replace(”/(rn|n|r)/”, “”, $text); //replace new line characters, important!
if($length==0){
return $text.”…”;
}
$words = explode(” “,$text); //convert text to array of words for count
for($i=0;$i<$length;$i++){ $introtext .= $words[$i]." "; //make HTML safe string for overlib popup } rtrim($introtext," "); //trim trailing space. if(!$tooltip_images){ $introtext = preg_replace("/]+>/i”, “”, $introtext);
}
$introtext = $introtext . “…”; //add …
return $introtext;
}
}
if(!function_exists(”getAuthorName”)){
//return authors name
function getAuthorName($id){
global $database;
$query = “SELECT name”
. “n FROM #__users”
. “n WHERE id = $id”
;
$database->setQuery( $query );
if ($name=$database->loadResult()){
return $name;
}
else{
return false;
}
}
}
if(!function_exists(”buildTooltip”)){
//make the tooltip content, wrap content in styleable css spans
function buildTooltip($item, $tooltip_created, $tooltip_created_date_format, $tooltip_author, $tooltip_intro, $tooltip_intro_word_count, $tooltip_images){
$text=””;
if($tooltip_created == ‘yes’){
$text.= “” . strftime($tooltip_created_date_format, strtotime($item[’date’])). “
“;}
if($tooltip_author == ‘yes’){
$author=getAuthorName($item[’author’]);
if($author){
$text .= “” . $author . “
“;}
}
if($tooltip_intro == ‘yes’){ $text.= “” . getIntroText($item[’introtext’],$tooltip_intro_word_count, $tooltip_images) . ““;}
return htmlspecialchars(addslashes(str_replace(’,’,’,’,$text)));
}
}
//end function declarations
//get, process data and output content
$items=getContentItems($source, $id, $number, $order, $sort, $date_format, $tooltip_intro); //get content items array using module parameters
$output=array(); //buffer to hold content items
switch($type){
//determine type of link list to generate
case ‘1’: //plain list
$start_list = “”; //list starting tag
$end_list = “”; //list ending tag
$start_link = “”; //list item starting tag
$end_link = “
“; //list item ending tagbreak;
case ‘2’: //bulleted
$start_list = “
- “;
$end_list = “
“;
$start_link = “
- “;
$end_link = “
“;
break;
case ‘3’: //numbered list
$start_list = “
- “;
$end_list = “
“;
$start_link = “
- “;
$end_link = “
“;
break;
default: //default to bulleted
$start_list = “
- “;
$end_list = “
“;
$start_link = “
- “;
$end_link = “
“;
break;
}
//custom stylesheet. edit ‘modules/mod_content_links.css’ to add custom style to the link list
echo ““;
if($enable_tooltip == ‘yes’){
//load support js library
mosCommonHTML::loadOverlib();
}
$output[’header’] = “
“; //start the block$output[’content’] = $start_list.”n”; //start the list
/* Key Content Generation Section */
//loop through and generate the html for selected content items
if(count($items)>0){
{
foreach($items as $item){if($enable_tooltip ==’yes’){
//generate tooltip content
$tooltip = “onmouseover=”overlib('”.buildTooltip($item, $tooltip_created, $tooltip_created_date_format, $tooltip_author, $tooltip_intro, $tooltip_intro_word_count, $tooltip_images).”‘, CAPTION, ‘”.addslashes(htmlspecialchars(preg_replace(”/(rn|n|r)/”, “”, $item[’title’]))).”‘, FGCOLOR, ‘”.$tooltip_fgcolor.”‘, BGCOLOR, ‘”.$tooltip_bgcolor.”‘, BORDER, “.$tooltip_border.”, CAPCOLOR, ‘”.$tooltip_capcolor.”‘, TEXTCOLOR, ‘”.$tooltip_textcolor.”‘”.$tooltip_extra_invocation_string.”);” onmouseout=”return nd();” “;}
else{
$tooltip = “”;
}
$output[’content’] .= $start_link; //start link html
$output[’content’] .= ““.$item[’title’].””;
$q4 = “SELECT catid FROM dutchbux_content WHERE sectionid=’$id’ AND state = 1 ORDER BY publish_up DESC LIMIT 0,10”;
$result = mysql_query($q4);
while ($line = mysql_fetch_assoc($result)) {
foreach ($line as $col_value) {
$q5 = “SELECT title FROM dutchbux_categories WHERE id = ‘$col_value'”;
$resultaat = mysql_query($q5);
$fetch = mysql_fetch_assoc($resultaat);
}
$resul = $fetch[’title’];
$output[’content’] .= $fetch[’title’];
$output[’content’] .= ““; //generate SEF URL
}//show the date in the list too?
if($show_date==’yes’){
$output[’content’] .= “n
“.$item[’date’].”“.$end_link.”n”;}else{
$output[’content’] .= $end_link.”n”;
} //end link html depends on list_type
}
}
}
else{//if no id provided, give an error message
if(!$id){
$output[’content’] = “Please enter list source Content ID(s) in module settings“;
}
}
$output[’content’] .= “n”.$end_list.”n”; //end the list
$output[’footer’] = “
“; //end the block
//print out the nicely formatted link list
print $output[’header’]
. $output[’content’]
. $output[’footer’];
//done!
?>
06/11/2008 23:26 om 23:26 #537053Dit is natuurlijk een naald zoeken in ‘n hooiberg, flats, dit is de code, kijk maar wat… Iets specifieke aub. Je moet in ieder geval hier zijn denk ik. Ik ken je veldstructuur echter niet, maar zoiets kan het zijn:
Code:$output[’content’] .= “n
“.$item[’date’].”“.$end_link.”n”;}
Maak ‘n variabel aan die de categorie eruit haalt (meestal te maken dmv $var, en zet die erachter. Dan krijg je zoiets bv:Code:$output[’content’] .= “n
“.$item[’date’].”
Categorie: “. $item[’categorie’].” “.$end_link.”n”;}07/11/2008 15:57 om 15:57 #537054sorry, dacht dat ik erbij had gezet welk deel ik specifiek bedoelde niet dus.. en die variabel die de categorie ophaalt, moet die tussen de Code:foreach($items as $item){
staan?
08/11/2008 07:28 om 07:28 #537055die zul je idd wel even erbij moeten zetten als die niet wordt gefetcht, maa je kunt het uiteraard altijd proberen. 09/11/2008 14:47 om 14:47 #537056ik heb nu dit:
Code:if(count($items)>0){
$q = “SELECT catid FROM dutchbux_content WHERE sectionid=’$id’ AND state = 1 ORDER BY publish_up DESC LIMIT 0,10”;
$query = mysql_query($q);
{
foreach($items as $item)
{if($enable_tooltip ==’yes’){
//generate tooltip content
$tooltip = “onmouseover=”overlib('”.buildTooltip($item, $tooltip_created, $tooltip_created_date_format, $tooltip_author, $tooltip_intro, $tooltip_intro_word_count, $tooltip_images).”‘, CAPTION, ‘”.addslashes(htmlspecialchars(preg_replace(”/(rn|n|r)/”, “”, $item[’title’]))).”‘, FGCOLOR, ‘”.$tooltip_fgcolor.”‘, BGCOLOR, ‘”.$tooltip_bgcolor.”‘, BORDER, “.$tooltip_border.”, CAPCOLOR, ‘”.$tooltip_capcolor.”‘, TEXTCOLOR, ‘”.$tooltip_textcolor.”‘”.$tooltip_extra_invocation_string.”);” onmouseout=”return nd();” “;}
else{
$tooltip = “”;
}
while ($row = mysql_fetch_assoc($query))
{
$catid = $row[’catid’];
$q2 = “SELECT title FROM dutchbux_categories WHERE id = ‘$catid'”;
$query2 = mysql_query($q2);
while ($rij = mysql_fetch_assoc($query2))
{
$cattitel = $rij[’title’];
// $output[’content’] .= $cattitel;}
//$output[’content’] .= $cattitel;
}$output[’content’] .= $start_link; //start link html
$output[’content’] .= ““.$item[’title’].”$cattitel”;
$output[’content’] .= ““; //generate SEF URL
}}
het enige probleem dat ik nu heb is dat achter mijn titels altijd dezefde categorie wordt weergegeven, terwijl als ze apart print met $output .= $cattitel; dat ze wel correct achter elkaar worden weergegeven. Maar van zodra ik ze achter een titel wil zetten veranderd het overal naar dezefde categorie.AuteurBerichten5 berichten aan het bekijken - 1 tot 5 (van in totaal 5)- Je moet ingelogd zijn om een antwoord op dit onderwerp te kunnen geven.
- “;