Phpost

Versión completa: Noticia diferente por página
Actualmente estas viendo una versión simplificada de nuestro contenido. Ver la versión completa con el formato correcto.
Si en el modulo de la noticia global está así:

{if $tsConfig.news}
   {foreach from=$tsConfig.news key=i item=n}
      {$n.not_body}
   {/foreach}
{/i}

Y en administración tengo 5 noticias activas.
Pero quiero mostrar una noticia diferente en cada página por medio del id de la noticia, ¿Cómo lo hago?
Hola, esto es lo que haría.
1 - Ejecuto esta consulta, con esto guardaremos la/s pagina/s que deseamos, ejemplo: home (una pagina) otra forma home,portal (dos o más paginas) y si se deja vacio, será de manera global!
 
Código:
ALTER TABLE `w_noticias` ADD `not_pages` VARCHAR(32) NOT NULL DEFAULT '' AFTER `not_active`;


2 - En c.admin.php modificar las siguientes funciones
 
Código PHP:
function getNoticia() {...}
function 
newNoticia() {...}
function 
editNoticia() {...} 

por estas funciones
 
Código PHP:
     /*
     getNoticia()
     */
    function getNoticia() {
        global $tsCore;
        //
        $not_id $tsCore->setSecure($_GET['nid']);
        //
        $query db_exec([__FILE____LINE__], 'query''SELECT `not_id`, `not_body`, `not_date`, `not_active`, `not_pages` FROM w_noticias WHERE not_id = \''  (int)$not_id '\' LIMIT 1');
        $data db_exec('fetch_assoc'$query);
        //
        return $data;
    }
     /*
     newNoticia()
     */
    function newNoticia() {
        global $tsCore$tsUser;
        //
        $not_body $tsCore->setSecure($tsCore->parseBadWords(substr($_POST['not_body'], 0190)));
        $not_active = empty($_POST['not_active']) ? 1;
        $not_pages $tsCore->setSecure($_POST['not_pages']);
        if (!empty($not_body)) {
            if (db_exec([__FILE____LINE__], 'query''INSERT INTO `w_noticias` (`not_body`, `not_autor`, `not_date`, `not_active`, `not_pages`) VALUES (\'' $not_body '\', \'' $tsUser->uid '\', \'' time() . '\', \'' $not_active '\', \'' $not_pages '\')'))
                 return true;
        }
        //
        return false;
     }
     /*
     editNoticia()
     */
    function editNoticia() {
        global $tsCore$tsUser;
        //
        $not_id intval($_GET['nid']);
        $not_body $tsCore->setSecure($tsCore->parseBadWords(substr($_POST['not_body'], 0190)));
        $not_active = empty($_POST['not_active']) ? 1;
        $not_pages $tsCore->setSecure($_POST['not_pages']);
        //
        if (!empty($not_body)) {
            if (db_exec([__FILE____LINE__], 'query''UPDATE `w_noticias` SET `not_autor` = \'' $tsUser->uid '\', `not_body` = \'' $not_body '\', not_active = \'' $not_active '\', not_pages = \'' $not_pages '\' WHERE not_id = \'' . (int)$not_id '\'')) return true;
        }
    


3 - En c.core.php buscar
 
Código PHP:
function getNews() {...} 

y reemplazar toda la función.
 
Código PHP:
    public function getNews() {
        global $tsPage;
        $query result_array(db_exec([__FILE____LINE__], 'query'"SELECT not_body, not_pages FROM w_noticias WHERE not_active = 1 ORDER BY RAND() LIMIT 5"));
        $tsPage $tsPage ?? $GLOBALS['_GET']['do'];
        $data = [];
        foreach ($query as $nid => $new) {
            $pages array_map('trim'explode(','$new['not_pages']));
            if ((empty($new['not_pages']) OR $tsPage === $new['not_pages']) OR in_array($tsPage$pages)) {
                $data[]['not_body'] = $this->parseBBCode($new['not_body'], 'news');
            }
        }
        return $data;
    


4 - En themes/default/templates/admin_mods/m.admin_noticias.tpl buscar
 
Código:
            <dl>
                <dt><label for="ai_not_active">Activar noticia:</label><br /><span>Activar inmediatamente esta noticia en {$tsConfig.titulo}.</span></dt>

y arriba añadir
Código:
            <dl>
                <dt><label for="ai_pages">En pagina:</label><br /><span>Donde deseas que se muestre la noticia.</span></dt>
                <dd><input type="text" id="ai_pages" name="not_pages" placeholder="home,portal,perfil,etc" value="{$tsNew.not_pages}" /></dd>
            </dl>
Gracias lo probaré