TinyPortal

Development => Support => Topic started by: zsolteey on November 21, 2015, 09:16:35 PM

Title: Articles in a category order by
Post by: zsolteey on November 21, 2015, 09:16:35 PM
Hi,

I'm using SMF 2.0.11 and TP 1.1.
I created an "article in a category" box named News. This displays the articles by the creation date. So the oldest articles is the first in the box. I want the opposite of this. I want to show the newest created article in the first place.
How can I achive that?

Thank you.

Sincerely,
Zsolteey.
Title: Re: Articles in a category order by
Post by: zsolteey on November 22, 2015, 01:49:09 PM
Quote from: zsolteey on November 21, 2015, 09:16:35 PM
Hi,

I'm using SMF 2.0.11 and TP 1.1.
I created an "article in a category" box named News. This displays the articles by the creation date. So the oldest articles is the first in the box. I want the opposite of this. I want to show the newest created article in the first place.
How can I achive that?

Thank you.

Sincerely,
Zsolteey.

Anybody knows where is the function which collects the data from the database to the "article in category" box?
Maybe I can modify the SQL query to order it to right way but I don't know where I can find it.

Thank you!
Title: Re: Articles in a category order by
Post by: wildenborch on November 22, 2015, 06:00:16 PM
I probably don't understand what you are asking but the sorting of articles is a setting within the category.

Title: Re: Articles in a category order by
Post by: zsolteey on November 22, 2015, 10:09:56 PM
Quote from: wildenborch on November 22, 2015, 06:00:16 PM
I probably don't understand what you are asking but the sorting of articles is a setting within the category.

Okkay, I try to clarify :)

I have a category named NewsCategory. I have for example two article in this category. On the attached screenshot you can see it (it's in hungarian language):
"Teszt" is created yesterday at 23:50 (yesterday is tegnap in hungarian).
"Új funkciók az oldalon" is created at 2015.11.18.

If I open the category it looks fine, "Teszt" is the first and "Új funkciók az oldalon" is the second. It's perfect.

But if you see the left block named "Hírek" (Hírek is News in english) the order is wrong. In this box I want to see the order as in the category page. So I want "Teszt" in the first place, "Új funkciók az oldalon is the second".
("Frissült a fórum" is the oldest article so it had to be the last in this list.).

This "Hírek" is an "Article in a category" block in the TP admin. If I open this block settings there is no option to change sort order.
So I want to find a solution to change my article in a category block sort order.

Can you help me?

Thank you!
Title: Re: Articles in a category order by
Post by: wildenborch on November 22, 2015, 10:34:27 PM
So Hirek is some kinf of "latest articles block"?

This is a latest article block I use on one of my sites

// Configuration

// Specify your categories, comma separated if more than one category.
$categories = array(1,2,44,135,22,117,114,77,18);

// End Config


// The heading area.

echo '
<br />';

// Now for the code...
global $scripturl, $db_prefix, $smcFunc;

$request = $smcFunc['db_query']('', '
SELECT id, date, subject, views, shortname
FROM {db_prefix}tp_articles
WHERE category IN ({array_int:cats})
                AND approved = 1
AND off = 0
ORDER BY date DESC
LIMIT 10',
array('cats' => $categories)
);

echo '
<table class="tborder" width="100%">
   <tr class="titlebg">
      <td>Onderwerp</td>
      <td>Datum</td>
      <td align="center">Bekeken</td>
   </tr>';

while ($row = $smcFunc['db_fetch_assoc']($request))
{
   if ($row['shortname'])
   {
      $pageid = $row['shortname'];
   }
   else
   {
      $pageid = $row['id'];
   }

   echo '
   <tr class="windowbg">
      <td style="padding: 3px 0px 3px 10px"><strong><a href="' , $scripturl, '?page=' , $pageid , '">' , $row['subject'] , '</a></strong></td>
      <td style="padding: 3px 0px 3px 10px">' , date('d-m-Y', $row['date']) , '</td>
      <td align="center" style="padding: 3px 0px 3px 15px">' , $row['views'] , '</td>
   </tr>
';
}

echo '
</table>';

$smcFunc['db_free_result']($request);


Maybe you can try this code?

Fred
Title: Re: Articles in a category order by
Post by: wildenborch on November 22, 2015, 10:34:48 PM
Quote from: wildenborch on November 22, 2015, 10:34:27 PM
So Hirek is some kind of "latest articles block"?

This is a latest article block I use on one of my sites

// Configuration

// Specify your categories, comma separated if more than one category.
$categories = array(1,2,44,135,22,117,114,77,18);

// End Config


// The heading area.

echo '
<br />';

// Now for the code...
global $scripturl, $db_prefix, $smcFunc;

$request = $smcFunc['db_query']('', '
SELECT id, date, subject, views, shortname
FROM {db_prefix}tp_articles
WHERE category IN ({array_int:cats})
                AND approved = 1
AND off = 0
ORDER BY date DESC
LIMIT 10',
array('cats' => $categories)
);

echo '
<table class="tborder" width="100%">
   <tr class="titlebg">
      <td>Onderwerp</td>
      <td>Datum</td>
      <td align="center">Bekeken</td>
   </tr>';

while ($row = $smcFunc['db_fetch_assoc']($request))
{
   if ($row['shortname'])
   {
      $pageid = $row['shortname'];
   }
   else
   {
      $pageid = $row['id'];
   }

   echo '
   <tr class="windowbg">
      <td style="padding: 3px 0px 3px 10px"><strong><a href="' , $scripturl, '?page=' , $pageid , '">' , $row['subject'] , '</a></strong></td>
      <td style="padding: 3px 0px 3px 10px">' , date('d-m-Y', $row['date']) , '</td>
      <td align="center" style="padding: 3px 0px 3px 15px">' , $row['views'] , '</td>
   </tr>
';
}

echo '
</table>';

$smcFunc['db_free_result']($request);


Maybe you can try this code?

Fred
Title: Re: Articles in a category order by
Post by: zsolteey on November 22, 2015, 10:52:27 PM
Quote from: wildenborch on November 22, 2015, 10:34:27 PM
So Hirek is some kinf of "latest articles block"?

This is a latest article block I use on one of my sites

// Configuration

// Specify your categories, comma separated if more than one category.
$categories = array(1,2,44,135,22,117,114,77,18);

// End Config


// The heading area.

echo '
<br />';

// Now for the code...
global $scripturl, $db_prefix, $smcFunc;

$request = $smcFunc['db_query']('', '
SELECT id, date, subject, views, shortname
FROM {db_prefix}tp_articles
WHERE category IN ({array_int:cats})
                AND approved = 1
AND off = 0
ORDER BY date DESC
LIMIT 10',
array('cats' => $categories)
);

echo '
<table class="tborder" width="100%">
   <tr class="titlebg">
      <td>Onderwerp</td>
      <td>Datum</td>
      <td align="center">Bekeken</td>
   </tr>';

while ($row = $smcFunc['db_fetch_assoc']($request))
{
   if ($row['shortname'])
   {
      $pageid = $row['shortname'];
   }
   else
   {
      $pageid = $row['id'];
   }

   echo '
   <tr class="windowbg">
      <td style="padding: 3px 0px 3px 10px"><strong><a href="' , $scripturl, '?page=' , $pageid , '">' , $row['subject'] , '</a></strong></td>
      <td style="padding: 3px 0px 3px 10px">' , date('d-m-Y', $row['date']) , '</td>
      <td align="center" style="padding: 3px 0px 3px 15px">' , $row['views'] , '</td>
   </tr>
';
}

echo '
</table>';

$smcFunc['db_free_result']($request);


Maybe you can try this code?

Fred

Yes, it is.
There is a built in "Article in a category" block type in TP as you can see the attached picture.
I just added this block and selected "Hírek" as source. 

I try your code tomorrow, thank you :)