TinyPortal

Development => Support => Topic started by: taucher on April 08, 2008, 08:45:48 PM

Title: Sort Order for Articles
Post by: taucher on April 08, 2008, 08:45:48 PM
Is ist possible to sort Articles in Categories by "Title"? I cant find it.
I would need that, becaus some of my Article Categories are like a "Lexicon"

Thanks for your hints.
Title: Re: Sort Order for Articles
Post by: ed_m2 on April 08, 2008, 09:17:17 PM
oh well.. shall i  ;)

i have a block from the 'recent articles (http://www.tinyportal.net/index.php?topic=3320.60)' code snippets cos thats what i want.
a quick peek at the code and it seems pretty easy to get what you want with a phpbox:


$articles=db_query("SELECT id,subject,author,category FROM smf_tp_articles WHERE approved=1 AND off=0 ORDER BY date DESC", __FILE__, __LINE__);
$cnt=0;
echo '<div class="smalltext">';
While ($row=mysql_fetch_row($articles)) {
   // The number of articles you want displayed
   if ($cnt < 5) {
       if ($row[3] != 12 && $row[3] != 15)  {
          echo '<b><a href="http://www.SITEURL/index.php?page=' . $row[0] . '">' . $row[1] . '</a></b> by ' . $row[2] . '<br /><br />';
        }
    }
   $cnt++;
}
echo '</div>';


set SITEURL to your own site so the link works correctly.

and change the first line to:

$articles=db_query("SELECT id,subject,author,category FROM smf_tp_articles WHERE approved=1 AND off=0 ORDER BY subject DESC", __FILE__, __LINE__);


subject being the field name for the article title.
ASC for A-Z (ascending) and DESC for Z-A (descending)

probably more refinements in the query & output format to be done but that works for me.
Title: Re: Sort Order for Articles
Post by: JPDeni on April 08, 2008, 09:41:15 PM
Quoteset SITEURL to your own site so the link works correctly.
Actually, it would be better to start your code with


global $scripturl;


And use this for your link


echo '<b><a href="' . $scripturl . '?page=' . $row[0] . '">


That way no one has to alter the code in order to use it.
Title: Re: Sort Order for Articles
Post by: ed_m2 on April 09, 2008, 08:13:57 AM
thanks.

must have missed that in the original code snippet, hence hacked it to work for my site the quickest way possible.
Title: Re: Sort Order for Articles
Post by: taucher on April 09, 2008, 07:00:11 PM
that means i have to place a block somewhere?
isnt it possible to hack the code, so that i can choose the sortorder "by title" in the tp-article admin?
i think that would be nice, or not?
Title: Re: Sort Order for Articles
Post by: ed_m2 on April 09, 2008, 10:56:39 PM
yeh that goes in a php block.

if you want to return articles only in a certain category you'll need to add that term to the query string at the top.

not 100% sure what decides the article order in a categorybox.
its in the function TPortal_categorybox() in TPortalblocks.template.php..... but it's not a regular SQL query so i dont follow it.
Title: Re: Sort Order for Articles
Post by: taucher on April 10, 2008, 08:55:03 PM
in fact im not very good (hm quite not even a beginner) in php its very difficult for me.

i found
the sorting for categories in tportal.php

which says:
// get the sorting from the category
if(in_array($context['TPortal']['article_categories'][$mycat]['options']['sort'], array('date','authorID','id','parse')))
$catsort = $context['TPortal']['article_categories'][$mycat]['options']['sort'];


so in the second line of this code, after 'date' i could insert 'subject' hm - but then?

is it possible to do this in this way?
Title: Re: Sort Order for Articles
Post by: taucher on April 13, 2008, 12:37:01 PM
ok, it is possible and i found the solution, so if someone other needs this here my changes:

In Sources/TPortal.php

find

// get the sorting from the category
if(in_array($context['TPortal']['article_categories'][$mycat]['options']['sort'], array('date','authorID','id','parse')))
$catsort = $context['TPortal']['article_categories'][$mycat]['options']['sort'];


and replace with

// get the sorting from the category
if(in_array($context['TPortal']['article_categories'][$mycat]['options']['sort'], array('date','subject','authorID','id','parse')))
$catsort = $context['TPortal']['article_categories'][$mycat]['options']['sort'];


In Themes/default/TPortalAdmin.template.php
find

<select name="tp_categories_sorting'.$mg['id'].'">
<option value="date"' , $mg['options']['sort']=='date' ? ' selected="selected"' : '' , '>' , $txt['tp-sortoptions1'] , '</value>


and add after

<option value="subject"' , $mg['options']['sort']=='subject' ? ' selected="selected"' : '' , '>' , $txt['tp-sortoptions5'] , '</value>

In Themes/default/languages/TPortalAdmin.english.php
find

$txt['tp-sortoptions4'] = 'Sort by id number';

and add after

$txt['tp-sortoptions5'] = 'Sort by subject';

Now you are able to choose this options in the Article Category Admin Section in TinyPortal.
Title: Re: Sort Order for Articles
Post by: ed_m2 on April 13, 2008, 04:55:28 PM
snazzy. well done.
Title: Re: Sort Order for Articles
Post by: taucher on April 13, 2008, 07:02:38 PM
thanks