Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • sjmorris Friend
    #146085

    Hi,

    I really like the look of ja_news2 and I would like it to only show categories from selected sections that have the newest articles.

    So for example, right now I have it showing a 5 sections (with three rows each) that have multiple categories in them, but it only displays the first three categories from each section – the others remain hidden unless I configure it to show more columns. I’d like it to show the three categories with the most recent posts in them, from newest to oldest.

    Possible?

    S

    zorroh Friend
    #323850
    sjmorris Friend
    #326174

    Bump.. just wondering if anyone can help?

    sjmorris Friend
    #326313

    Got a programmer savvy guy to fix this. Joomlart devs, I’m disappointed you couldn’t help us out but at least add this to the next rev of the code:

    In helper.php:

    FIND:

    $query = “SELECT `id`, `title`, `description`, CASE WHEN CHAR_LENGTH(`alias`) THEN CONCAT_WS(“:”, `id`, `alias`) ELSE `id` END as `slug` FROM `#__categories` s WHERE published = 1 and section=” . ( int ) $sid . $where;

    $query .= ” ORDER BY s.ordering ASC”; //$query .= ” ORDER BY s.id ASC”;

    REPLACE WITH:

    $query = “SELECT s.id as id, s.title as title, s.description as description, CASE WHEN CHAR_LENGTH(s.alias) THEN CONCAT_WS(‘:’, s.id, s.alias) ELSE s.id END as slug FROM jos_content a, jos_categories s WHERE a.catid = s.id AND s.section={$sid} {$where} GROUP BY a.catid ORDER BY MAX(a.created) DESC”;

    Works for me.

    S

    kryptos Friend
    #327267

    <em>@sjmorris 156479 wrote:</em><blockquote>
    $query .= ” ORDER BY s.ordering ASC”; //$query .= ” ORDER BY s.id ASC”;

    </blockquote>

    there is no such a string in my helper.php file :confused:

    sjmorris Friend
    #327270

    /joomla/modules/mod_janews2/helper.php

    Not sure what else to do here – unless they have updated this module since I downloaded it. PM me your email and I’ll send you a copy of mine.

    kryptos Friend
    #327272

    I have 1.3 version.
    I’ll check out the newest one…

    edit:

    i’ve just downloaded version 1.4, but no, still there is no such a string in helper.php file.

    Saguaros Moderator
    #327473

    it’s at line 421 inside the loadCategories function, please try to find again 🙂

    James Waddell Friend
    #328165

    I have inserted the code as recommended for the function (see below):
    function loadCategories($sid) {
    $categories = array ();
    $catids = $this->getUserSetting ( $sid, ‘categories’ );

    $where = ”;
    $limit = 0;
    if ($catids) {
    if (is_array ( $catids ))
    $where .= ” AND `id` in (” . implode ( ‘,’, $catids ) . “)”;
    } else {
    if (is_array ( $this->getUserSetting ( $sid ) ))
    $where = ” AND 0″;
    else
    $limit = ( int ) $this->get ( ‘cols’, 2 );
    }

    $db = & JFactory::getDBO ();
    /*
    Commented out on 4 Jan 2010 and inserted code from http://www.joomlart.com/forums/topic/ja_news2-only-show-categories-with-new-articles/
    $query = “SELECT `id`, `title`, `description`, CASE WHEN CHAR_LENGTH(`alias`) THEN CONCAT_WS(“:”, `id`, `alias`) ELSE `id` END as `slug` FROM `#__categories` s WHERE published = 1 and section=” . ( int ) $sid . $where;
    */
    $query = “SELECT s.id as id, s.title as title, s.description as description, CASE WHEN CHAR_LENGTH(s.alias) THEN CONCAT_WS(‘:’, s.id, s.alias) ELSE s.id END as slug FROM jos_content a, jos_categories s WHERE a.catid = s.id AND s.section={$sid} {$where} GROUP BY a.catid ORDER BY MAX(a.created) DESC”;
    $db->setQuery ( $query, 0, $limit );
    $rows = $db->loadObjectList ( ‘id’ );
    foreach ( $rows as $cid => $row ) {
    $obj = new stdclass ( );
    $obj->category = $row;
    $categories [] = $obj;
    }
    return $categories;
    }

    It works perfectly for some sections. However on two sections I am getting the error message on the Frontpage:
    “Warning: Invalid argument supplied for foreach() in C:xampphtdocsbtm_29_dec_2009modulesmod_janews2helper.php on line 428”

    Line 428 is: foreach ( $rows as $cid => $row ) {

    The section title is displayed.

    Any ideas on this as there is nothing special about the sections causing the error as they worked OK with the original code that I have now commented out.

    glitter Friend
    #355745

    Hello,

    I’m very intrested to ordering and showing categories that have the newest articles only (Category order will change as has newest article). That will make the news more interactive in the categories.

    The code is working but I’m also have same error:

    Warning: Invalid argument supplied for foreach() in …modules/mod_janews2/helper.php on line 431
    ( in my file 431 = foreach ( $rows as $cid => $row ) { )

    So, please could you solve it?

    Saguaros Moderator
    #355777

    <em>@glitter 194297 wrote:</em><blockquote>Hello,

    I’m very intrested to ordering and showing categories that have the newest articles only (Category order will change as has newest article). That will make the news more interactive in the categories.

    The code is working but I’m also have same error:

    Warning: Invalid argument supplied for foreach() in …modules/mod_janews2/helper.php on line 431
    ( in my file 431 = foreach ( $rows as $cid => $row ) { )

    So, please could you solve it?</blockquote>

    Hello, please try following to the thread #4 http://www.joomlart.com/forums/topic/ja_news2-only-show-categories-with-new-articles/#post-326313

    Sherlock Friend
    #355811

    <em>@glitter 194297 wrote:</em><blockquote>Hello,

    I’m very intrested to ordering and showing categories that have the newest articles only (Category order will change as has newest article). That will make the news more interactive in the categories.

    The code is working but I’m also have same error:

    Warning: Invalid argument supplied for foreach() in …modules/mod_janews2/helper.php on line 431
    ( in my file 431 = foreach ( $rows as $cid => $row ) { )

    So, please could you solve it?</blockquote>

    Dear glitter,

    I am afraid that it is hard to do as you want,it will need a heavy custom work !

    glitter Friend
    #355829

    I replaced the code:

    <blockquote>In helper.php:

    FIND:

    $query = “SELECT `id`, `title`, `description`, CASE WHEN CHAR_LENGTH(`alias`) THEN CONCAT_WS(“:”, `id`, `alias`) ELSE `id` END as `slug` FROM `#__categories` s WHERE published = 1 and section=” . ( int ) $sid . $where;

    $query .= ” ORDER BY s.ordering ASC”; //$query .= ” ORDER BY s.id ASC”;

    REPLACE WITH:

    $query = “SELECT s.id as id, s.title as title, s.description as description, CASE WHEN CHAR_LENGTH(s.alias) THEN CONCAT_WS(‘:’, s.id, s.alias) ELSE s.id END as slug FROM jos_content a, jos_categories s WHERE a.catid = s.id AND s.section={$sid} {$where} GROUP BY a.catid ORDER BY MAX(a.created) DESC”;</blockquote>

    It’s working, but if user change the setting, the hole section will hidden and the message error will appear again:

    Warning: Invalid argument supplied for foreach() in /home/…/public_html/…/modules/mod_janews2/helper.php on line 431

    If it’s hard and need a heavy custom work, may it’s good suggestion for new feature in coming ja_news version!

    Thanks tienhc & dathq 🙂

    glitter Friend
    #355920

    The problem of foreach() statement occurred if the user try to change the default setting, so may we need two different queries to order the categories:
    (1) Default categories order to show categories that have the newest articles.
    (2) User categories order to show them as user choices.

    I tried the following code by if statement. It’s working:


    function loadCategories($sid) {
    $categories = array ();
    $catids = $this->getUserSetting ( $sid, 'categories' );

    $where = '';
    $limit = 0;
    if ($catids) {
    if (is_array ( $catids ))
    $where .= " AND `id` in (" . implode ( ',', $catids ) . ")";
    } else {
    if (is_array ( $this->getUserSetting ( $sid ) ))
    $where = " AND 0";
    else
    $limit = $this->get( 'max_categories_display' , 3 );
    }

    $db = & JFactory::getDBO ();

    if (is_array ( $this->getUserSetting ( $sid ) ) <>3 ) {
    $query = "SELECT s.id as id, s.title as title, s.description as description, CASE WHEN CHAR_LENGTH(s.alias) THEN CONCAT_WS(':', s.id, s.alias) ELSE s.id END as slug FROM jos_content a, jos_categories s WHERE a.catid = s.id AND s.section={$sid} {$where} GROUP BY a.catid ORDER BY MAX(a.created) DESC";
    } else {
    $query = "SELECT `id`, `title`, `description`, CASE WHEN CHAR_LENGTH(`alias`) THEN CONCAT_WS(":", `id`, `alias`) ELSE `id` END as `slug` FROM `#__categories` s WHERE published = 1 and section=" . ( int ) $sid . $where .' ORDER BY s.ordering';
    }

    $db->setQuery ( $query, 0, $limit );
    $rows = $db->loadObjectList ( 'id' );
    foreach ( $rows as $cid => $row ) {
    $obj = new stdclass ( );
    $obj->category = $row;
    $categories [] = $obj;
    }
    return $categories;
    }

    pontikoua Friend
    #396799

    Is working for me

Viewing 15 posts - 1 through 15 (of 15 total)

This topic contains 15 replies, has 8 voices, and was last updated by  pontikoua 12 years, 10 months ago.

We moved to new unified forum. Please post all new support queries in our New Forum