RANDOMARTICLE_ALIAS/ID

A quite simple solution to show a random article by alias- or id and show the result at the place of the TAGs {RANDOMARTICLE_ALIAS} / {RANDOMARTICLE_ID}.



rt_random_article_alias V1.0 18.07.10

Docu: –
Forum: http://forum.phpwcms.org/viewtopic.php?f=28&t=20397

Author: K.Heermann (flip-flop) http://planmatrix.de
CMS Version: >= 1.3
Version: V1.0

TAGs: {RANDOMARTICLE_ALIAS} and {RANDOMARTICLE_ID}

Fileiname: rt_random_article_alias.php

Folder: template/inc_script/frontend_render/

Condition:/config/phpwcms/conf.inc.php

  • $phpwcms['allow_ext_render'] = 1;



Script:

rt_random_article_alias

<?php
 
/**
*********************************************************************************************
* 18.07.10 KH: http://planmatrix.de V1.0
* frontend_render-Script: Random article alias/id
* TAGs: {RANDOMARTICLE_ALIAS} and {RANDOMARTICLE_ID}
*********************************************************************************************
*/
// -------------------------------------------------------------------------------------------
// obligate check for phpwcms constants
   if (!defined('PHPWCMS_ROOT')) {
      die("You Cannot Access This Script Directly, Have a Nice Day."); }
// -------------------------------------------------------------------------------------------
 
if (strpos($content["all"], '{RANDOMARTICLE_') ) {
 
    $hidden_article = ''; // CUSTOM: All not available article like '23,45,78,...'
 
    $c = 0;
    while ($c == 0) {
 
        // Artikel in der DB suchen
        // Search for the article in dba
        $sql  = "SELECT article_id, article_cid, article_alias ";
        $sql .= "FROM ".DB_PREPEND."phpwcms_article ";
        $sql .= "WHERE article_public=1 AND article_aktiv=1 AND article_deleted=0 ";
        $sql .= "AND (article_archive_status=1 AND article_begin<NOW() ";
        $sql .= "OR article_archive_status=0 AND article_end>NOW()) ";
        $sql .= (!empty($hidden_article))? "AND article_id NOT IN (".$hidden_article.") ":'';
        $sql .= "ORDER BY RAND() LIMIT 0,1";
 
        $result = _dbQuery($sql);
 
        if (!$content["struct"][$result['0']['article_cid']]['acat_regonly']) $c = 1;  // Break if the category is free for all
 
    }  // --- END while
 
    // Output alias
    $content["all"] = str_replace('{RANDOMARTICLE_ALIAS}',$result['0']['article_alias'],$content["all"] );
 
    // Output id
    $content["all"] = str_replace('{RANDOMARTICLE_ID}',$result['0']['article_id'],$content["all"] );
 
}
 
?>


  • In “$hidden_article” article IDs can be registered, which are excluded from selection. ('23,56,74,12,…') please use apostrophes at the beginning and end!
  • If you need the id instead of the alias, please uncomment the line below "// Output id" and comment the line below "// Output alias".

Update 19.07.2010 KH: Two TAGs {RANDOMARTICLE_ALIAS} and {RANDOMARTICLE_ID}.


english/phpwcms_replacer_rts/frontend_render/random-article-alias-id.txt · Last modified: 2010/07/19 07:45 by Knut Heermann (flip-flop)
www.planmatrix.de www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0