Když budu předpokládat, že $create_date je timestamp ze SL db
//Hack for showing "Today" and "Yesterday" by Kryštof Korb | Copyright August 2008
$lang = "cz"; //Language en, cz, fr
$create_date = date("Y-m-d",$create_date);
$today['en'] = 'Today!';
$today['cz'] = 'Dnes!';
$today['fr'] = 'Aujourd\'hui!';
$yesterday['en'] = 'Yesterday';
$yesterday['cz'] = 'Včera';
$yesterday['fr'] = 'Hier';
if ($create_date == date("Y-m-d", strtotime("now"))) {
$create_date = '<span style="color: red;">' . $today[$lang] . '</span>';
}
if ($create_date == date("Y-m-d", strtotime("1 day ago"))) {
$create_date = '<span style="color: red;">' . $yesterday[$lang] . '</span>';
}
//End of Today/Yesterday hackSamozřejmě s tím, že v SL se ještě jinak používá lang, ale to by bylo na delší vysvětlování
Pro začátek bych to chtěl přidát aspoň do articlePreview pluginu ale nedaří 😞
Povedlo se v articlePreview pluginu jsme přidal
$create_date = date('d.m.Y', $art['time']);
$today = 'Dnes!';
$yesterday = 'Včera';
if ($create_date == date('d.m.Y', strtotime("now"))) {
$create_date = '<span style="color: red;">' . $today. '</span>';
}
if ($create_date == date('d.m.Y', strtotime("1 day ago"))) {
$create_date = '<span style="color: red;">' . $yesterday. '</span>';
}a místo
<span class='date'>".date('d.m.Y', $art['time'])."</span>jsem nahradil
<span class='date'>".$create_date."</span>a šlape. :-)
Ještě bych měl dotaz chtěl bych dolu mezi datum a kategorie umístit kategorii ale nedaří se mi to :-( poradíte?
<?php
/* --- kontrola jadra --- */
if(!defined('_core')) {
exit;
}
$GLOBALS['_odd']=true;
// funkce
function _plugin_articlePreview($art, $info, $perex, $comment_count)
{
global $_odd;
$status=((true===$_odd)?"odd":"even");
$link = _linkArticle($art['id'], $art['title_seo']);
// uprava datumu na dnes, vcara
$my_date = date('d.m.Y', $art['time']); // formatuje i datum pouze na den,mesic, rok
$today = 'Dnes';
$yesterday = 'Včera';
if ($my_date == date('d.m.Y', strtotime("now"))) {
$my_date = '' . $today. '';
}
if ($my_date == date('d.m.Y', strtotime("1 day ago"))) {
$my_date = '' . $yesterday. '';
}
// dalsi upravy na kategorie
$cat = DB::query("SELECT r.title FROM `"._mysql_prefix."-articles` a LEFT JOIN `"._mysql_prefix."-root` r ON ( a.home1 = r.id ) WHERE a.home1 = ".$art['id']." LIMIT 0 , 1 ");
$out = "
<div class='list-article num-{$status}'>
<div class='list-perex-media'>
".(($perex && isset($art['picture_uid'])) ? "<a href='{$link}'><img src='"._pictureStorageGet(_indexroot.'pictures/articles/', null, $art['picture_uid'], 'jpg')."' class='list-perex-image' alt='{$art['title']}' /></a>" : '')."
</div>
<h2 class='list-title'><a href='{$link}'>"._cutStr(_htmlStrUndo($art['title']), 70)."</a></h2>
".($perex ? "<p class='list-perex'>
"._cutStr(strip_tags(_parsePost(_htmlStrUndo($art['perex']))), 250)."
</p>" : '')."
".($info ? "<div class='list-info'>
<span class='date'>".$my_date."</span>
<span class='categories'>".$cat."</span>
<span class='comments'><img class='icon' alt='comment' src='./plugins/templates/default/images/icons/comment.gif'></img>".(isset($comment_count) ? " komentářů {$comment_count}" : '')."</span>
</div>" : '')."
</div>
<div class='hr_line'></div>";
if (true===$_odd){
$_odd=false;
}else{
$_odd=true;
}
return $out;
}
_extend('reg', 'article.preview', function($args) {
$args['callback'] .='_plugin_articlePreview';
});
Díky za další dožnosti jestli bych tě mohl poprosit s radou na ty kategorie uvítal bych to :-)
//dotaz
$article = DB::query_row("SELECT
a.id, a.title_seo, a.home1, a.home2, a.home3
FROM `"._mysql_prefix."-articles` a
WHERE a.id= ".DB::val($art['id']));
//zjistit v jakych je kategoriich
$categories="";
$homes = array();
for($i = 1; $i <= 3; ++$i) if ($article['home' . $i] != -1) $homes[] = $article['home' . $i];
$q = DB::query('SELECT id,title,title_seo,var3 FROM `' . _mysql_prefix . '-root` WHERE id IN(' . implode(',', $homes) . ')');
$homes = array();
$cat_showinfo = false;
while ($r = DB::row($q)) {
if ($r['id'] == $article['home1']) $homei = 1;
elseif ($r['id'] == $article['home2']) $homei = 2;
else $homei = 3;
$homes[$homei] = $r;
if ($r['var3'] == 1) $cat_showinfo = true;
}
for ($i = 1; $i <= 3; ++$i) {
if (!isset($homes[$i])) continue;
$homes[$i] = "<a href='" . _linkRoot($homes[$i]['id'], $homes[$i]['title_seo']) . "' class='list-category-link category-"._anchorStr($homes[$i]['title'])."'><span>" . $homes[$i]['title'] . "</span></a>";
}
$categories .= implode('', $homes);
unset($homes);
<div class='list-categories'>
{$categories}
</div>
Dík moc za ten kód, ale mám s tím problém :-( možná jsem to dal do špatné části pluginu
<?php
/* --- kontrola jadra --- */
if(!defined('_core')) {
exit;
}
$GLOBALS['_odd']=true;
// funkce
function _plugin_articlePreview($art, $info, $perex, $comment_count)
{
global $_odd;
$status=((true===$_odd)?"odd":"even");
$link = _linkArticle($art['id'], $art['title_seo']);
// uprava datumu na dnes, vcara
$my_date = date('d.m.Y', $art['time']); // formatuje i datum pouze na den,mesic, rok
$today = 'Dnes';
$yesterday = 'Včera';
if ($my_date == date('d.m.Y', strtotime("now"))) {
$my_date = '' . $today. '';
}
if ($my_date == date('d.m.Y', strtotime("1 day ago"))) {
$my_date = '' . $yesterday. '';
}
// kategorie
//dotaz
$article = DB::query_row("SELECT
a.id, a.title_seo, a.home1, a.home2, a.home3
FROM `"._mysql_prefix."-articles` a
WHERE a.id= ".DB::val($art['id']));
//zjistit v jakych je kategoriich
$categories="";
$homes = array();
for($i = 1; $i <= 3; ++$i) if ($article['home' . $i] != -1) $homes[] = $article['home' . $i];
$q = DB::query('SELECT id,title,title_seo,var3 FROM `' . _mysql_prefix . '-root` WHERE id IN(' . implode(',', $homes) . ')');
$homes = array();
$cat_showinfo = false;
while ($r = DB::row($q)) {
if ($r['id'] == $article['home1']) $homei = 1;
elseif ($r['id'] == $article['home2']) $homei = 2;
else $homei = 3;
$homes[$homei] = $r;
if ($r['var3'] == 1) $cat_showinfo = true;
}
for ($i = 1; $i <= 3; ++$i) {
if (!isset($homes)) continue;
$homes = "<a href='" . _linkRoot($homes['id'], $homes['title_seo']) . "' class='list-category-link category-"._anchorStr($homes['title'])."'><span>" . $homes['title'] . "</span></a>";
}
$categories .= implode('', $homes);
unset($homes);
$out = "
<div class='list-article num-{$status}'>
<div class='list-perex-media'>
".(($perex && isset($art['picture_uid'])) ? "<a href='{$link}'><img src='"._pictureStorageGet(_indexroot.'pictures/articles/', null, $art['picture_uid'], 'jpg')."' class='list-perex-image' alt='{$art['title']}' /></a>" : '')."
</div>
<h2 class='list-title'><a href='{$link}'>"._cutStr(_htmlStrUndo($art['title']), 70)."</a></h2>
".($perex ? "<p class='list-perex'>
"._cutStr(strip_tags(_parsePost(_htmlStrUndo($art['perex']))), 220)."
</p>" : '')."
".($info ? "<div class='list-info'>
<span class='date'>".$my_date."</span>
<span class='categorie'>{$categories}</span>
<span class='comments'><img class='icon' alt='comment' src='./plugins/templates/default/images/icons/comment.gif'></img>".(isset($comment_count) ? " komentářů {$comment_count}" : '')."</span>
</div>" : '')."
</div>
<div class='hr_line'></div>";
if (true===$_odd){
$_odd=false;
}else{
$_odd=true;
}
return $out;
}
_extend('reg', 'article.preview', function($args) {
$args['callback'] .='_plugin_articlePreview';
});pořád to vypisuje
Notice: Undefined index: id in articlePreview.php on line 59
Notice: Undefined index: title in articlePreview.php on line 59
Notice: Undefined index: title_seo in articlePreview.php on line 59
Po radíč mi co dělám špatně? Dík
Jo ten 59 řádek je
$homes = "<a href='" . _linkRoot($homes['id'], $homes['title_seo']) . "' class='list-category-link category-"._anchorStr($homes['title'])."'><span>" . $homes['title'] . "</span></a>";
}
V další revizi to půjde udělat systémově přes extend plugin.