NAVIGATION
This is an old revision of the document!
Aufgabenstellung:
An bestimmte Artikeln soll Inhalt aus einer eigenen Datenbank zur Laufzeit angefügt werden. Die ID des jeweiligen Artikels bestimmt den Inhalt in der DB.
Die Zuordnung soll sowohl im Artikellistenmodus wie auch im Artikeldetailmodus funktionieren.
Beispielsweise könnte das ein Kommentarfeld aus einer externen DB sein.
Ort der Ausgabe im Artikellistenmodus jeweils unterhalb des Schlagtextes, im Artikeldetailmodus unterhalb des letzten CPs.
Ich zeige wie der Inhalt ausgelesen und zugeordnet werden kann, nicht wie die Tabelle mit den richtigen Werten gefüllt wird!!
In diesem (sinnfreien) Beispiel wird exemplarisch die DB-Tabelle “phpwcms_country” verwendet, die in jeder Installation vorhanden ist.
Ich setzte die DB-Spalte “country_id” gleich mit der “Artikel-ID” um das Ergebnis zu erhalten.
Vorgehensweise:
Ein /frontend_render/ Script reagiert auf einen betimmten TAG und liefert das Ergebnis aus der DB an dieser Stelle aus. Mit dem TAG wird auch die Artikel-ID an das Script übergeben (Artikellistenmodus). Im Artikeldetailmodus wird die ID in der Systemvariablen “$aktion[1]” geliefert.
In den Artikel-Listen/Detail Templates wird eine Markierung <!--ARTICLE_COMMENT--> gesetzt um die betroffenen Artikel zu kennzeichnen. Alle Artikel die dieses Template verwenden werden also vom Script untersucht.
Im Artikellistentemplate wird der TAG <!--[%ARTICLE_LIST:{ARTICLEID}%]--> an der Ausgabestelle des DB-Inhalts gesetzt.
Für den Modus Artikeldetail wird in der Hauptvorlage der Seite direkt hinter {CONETNT} der TAG <!--%ARTICLE_COMMENT%--> gesetzt. So ist gewährleistet, dass die DB-Ausgabe hinter dem letzten CP steht. (Sonderfälle mit CUSTOM_BLOCKS bitte beachten).
Datei: temples/inc_cntpart/articlesummary/list/my_sample_list.tmpl
<!-- sample template for article summary listing =========================================== TITLE = article title SUB = article subtitle SUMMARY = article summary text IMAGE = summary image (only the <img src="..."> tag) ZOOMIMAGE = if the image is click-zoomable (<a href...><img...></a>) CAPTION = summary image caption ARTICLELINK = url to full article MORE = the "more..." text/image like defined in template_defaults BEFORE = show before listing entry AFTER = show after listing entry SPACE = show this between listings DATE = show article date {DATE:FORMAT:LANG} or {DATE:FORMAT} EDITOR = name of editor ARTICLEID = ID of list entry //--> [SPACE]<hr />[/SPACE] <div> <table cellspacing="0" cellpadding="0" border="0" width="100%" summary=""> <tr> <td width="150" valign="top"> [IMAGE]<div><a href="{ARTICLELINK}">{IMAGE}</a></div>[/IMAGE] [CAPTION]<div align="center">{CAPTION}</div>[/CAPTION] </td> <td width="10"><img src="img/leer.gif" border="0" width="10" height="1" alt="" /></td> <td width="98%" valign="top"> [TITLE]<h1 style="margin:0 0 5px 0;">{TITLE} (Article-ID={ARTICLEID})</h1>[/TITLE] [SUB]<h3 style="margin:0 0 5px 0;">{SUB}</h3>[/SUB] [SUMMARY]<p style="margin:0"><strong>{DATE:F d.m.Y lang=DE}</strong> {SUMMARY}</p>[/SUMMARY] [MORE]<a href="{ARTICLELINK}"{TARGET}>{MORE}</a>[/MORE] </td> </tr> </table> <!--[%ARTICLE_LIST:{ARTICLEID}%]--> </div>
Datei: temples/inc_cntpart/articlesummary/article/my_sample_detail.tmpl
<!-- sample custom full article summary template =========================================== TITLE = article title SUB = article subtitle SUMMARY = article summary text IMAGE = summary image, also click zoomable CAPTION = summary image caption DATE = show article date {DATE:FORMAT lang=LANG} or {DATE:FORMAT} CURRENT_ARTICLEID = ID of list entry //--> <div> {BROWSE:UP:^^^} - {XBROWSE:UP:^XXX^}<br> {BROWSE:PREV:<<<:1} - {BROWSE:NEXT:>>>:1} [PHP]//dumpVar($GLOBALS['aktion']);[/PHP] [TITLE]<h1 style="margin:0 0 5px 0;">{TITLE} (Article-ID={CURRENT_ARTICLEID})</h1>[/TITLE] [SUB]<h3 style="margin:0 0 5px 0;">{SUB}</h3>[/SUB] <p style="margin:0">[IMAGE]<span style="float:left;margin:2px 10px 8px 0;">{IMAGE}[CAPTION]<br>{SPACER:1x3}<br />{CAPTION}[/CAPTION]</span> [/IMAGE] <strong>{DATE:Y-m-d}</strong> {SUMMARY}</p> </div> <div style="clear:both";><!-- nix //--> </div> <!--ARTICLE_COMMENT-->
DB-Abfrage Country
template/inc_script/frontend_render/replace_articleid_with_db_query.php
replace_articleid_with_db_query
<?php /** ********************************************************************************************* * 25.10.10 KH: http://planmatrix.de V1.0 * Einfügen von DB-Inhalt in bestimmten Artikel mit ID selektion. ********************************************************************************************* */ // ------------------------------------------------------------------------------------------- // obligate check for phpwcms constants if (!defined('PHPWCMS_ROOT')) {die("You Cannot Access This Script Directly, Have a Nice Day."); } // ------------------------------------------------------------------------------------------- // TEST Artikel-Listenmodus: Artikel-ID String auslesen und ersetzen // <!--[%ARTICLE_LIST:{ARTICLEID}%]--> // Nur wenn in Artikel-Listenansicht und zu ersetzender String vorhanden if( ( empty($aktion[4]) AND !strpos($content["all"],'<!--[%ARTICLE_LIST:') === false) ) { $article_id = array(); preg_match_all('/\<!--\[%ARTICLE_LIST:(\d+)%\]--\>/s', $content["all"], $article_id); //dumpVar($article_id); // Nun anhand der IDs die DB abfragen und in einem zweiten Durchlauf jeweils einsetzen // .... DBabfrage //Layout fuer Ergebnis setzen $layout01 = '<div style="padding: 5px; margin: 10px 0 0 13px; width:520px; border: 1px solid blue; background: lightblue;">'; $layout02 = '</div>'; // <!--[%ARTICLE_LIST:XX%]--> esetzen $result = ''; if (isset($article_id[1][0])) { // TAG vorhanden? foreach ( $article_id[1] as $key=>$value) { $result = $layout01; $result .= 'Ergebnis zu DB-Abfrage mit der Nr. '.$value. ' // Result for db query with the No '.$value.LF; $result .= $layout02; $content['all'] = str_replace('<!--[%ARTICLE_LIST:'.$value.'%]-->',$result,$content['all']); } } } // TEST Artikel-Detailmodus: Artikel mit Kommentar ist mit <!--ARTICLE_COMMENT--> versehen // In der Vorlage an der entsprechenden Stelle den Platzhalter: <!--%ARTICLE_COMMENT%--> // Nur wenn in Artikel-Detailansicht und Artikel als Kommentarartikel gekennzeichnet if( !empty($aktion[4]) AND !( strpos($content["all"],'<!--ARTICLE_COMMENT-->') === false) ) { //Layout fuer Ergebnis setzen $layout01 = '<hr>'; $layout01 .= '<div style="padding: 5px; margin: 15px 0 15px 0; width:320px; border: 1px solid blue; background: lightblue;">'; $layout02 = '</div>'; $layout02 .= '<hr>'; // ...... // Den/die Kommentare aus der DB holen mit $article_id = $aktion[1]; //.... DB-Abfrage // Ergebnis einfuegen $result = $layout01; $result .= '- Ergebnis aus DBabfrage fuer Artikel-ID='.$article_id. '<br />'.LF. '- Result from db query for the article ID '.$article_id.LF; $result .= $layout02; $content["all"] = str_replace('<!--%ARTICLE_COMMENT%-->', $result, $content["all"]); } ?>