Archive List Configuration

Get help with installation and running PivotX 2.0.x here. Please do not post Extension or Theme related questions here.

Archive List Configuration

Postby arah » Thu Nov 10, 2011 7:55 pm

Hi!

I'd like a helping hand, if possible, with a little extra configuration of the archive list. I hope this is the correct subforum for this question.

I'd like to have the archive list printed in ascending order, with entry titles only.
As I understand from the docs, the following code should be used:
Code: Select all
[[archive_list order='asc' format='<li><a href="%url%"><em>NUMERAL</em> <strong>%title%</strong></a></li>']]   


Now, I'd like NUMERAL to be the entry # (UID?) in Roman Numerals.

Although I am by no means a coder, PHP scripts for arabic > roman numeral conversion out there abound, and are easy enough to understand even to a layman as myself. I picked, for example http://www.go4expert.com/forums/showthread.php?t=4948 - now however, I'd like to know, how I can tie this conversion script into the archive list.
I'd have to get the UID for each entry in the archive list, convert it to a roman numeral, and then print it in between the em tags in the archive list formatting.

Is that train of thought correct?
So I'd set it up like this:
Code: Select all
[[archive_list order='asc' format='<li><a href="%url%"><em><?php print numberToRoman(%uid%); ?> <strong>%title%</strong></a></li>']] -   

as according to the pivotX documentation, %uid% is supposed to return the UID of a given entry.

Am I supposing all of this correctly? Or can %uid% not be used this way in an archive list?

Thanks!
arah
 
Posts: 4
Joined: Thu Nov 10, 2011 7:21 pm

Re: Archive List Configuration

Postby hansfn » Thu Nov 10, 2011 9:18 pm

You have misunderstood the purpose of the archive_list tag - it lists weekly or monthly archives - see our documentation. (It's not a list of entries.) And I can't see where we say that %title% and %uid% is supported ...

To get a list of entry titles, you need to use a subweblog.
hansfn
Developer
 
Posts: 3072
Joined: Sun Nov 25, 2007 7:48 pm
Location: Molde, Norway

Re: Archive List Configuration

Postby arah » Thu Nov 10, 2011 9:56 pm

Righty-ho. Thanks!

After reading through the docs on subweblogs, I got everything working, except for handing [[$entry.uid]] to the php function.
Can php and pivotX tags/variables be mixed?
When used within the boundaries of the [[php]] tag, square brackets need to be escaped by means of single or double quotes('[[$entry.uid]]'), which seems to break the pivotX variable. pivotX tags/variables do not seem to be parsed any longer.
arah
 
Posts: 4
Joined: Thu Nov 10, 2011 7:21 pm

Re: Archive List Configuration

Postby arah » Fri Nov 11, 2011 5:52 pm

For the record, and to be of use to future users:

I solved the issue by modifying /pivotx/modules/module_smarty.php to include the following:

Where functions be registered, I added
Code: Select all
 // Smarty functions..
$this->register_function('rid''smarty_rid');
 


and at the appropriate alphabetic position in the code block where the functions be declared, I added
Code: Select all
/**
 * Returns the uid for the current entry in roman numerals
 *
 * @param array $params
 * @param object $smarty
 * @return string
 */

// A function to return the Roman Numeral, given an integer
 function numberToRoman($num)
 {
     // Make sure that we only use the integer portion of the value
     $n = intval($num);
     $result = '';
 
     
// Declare a lookup array that we will use to traverse the number:
     $lookup = array('M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400,
     'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40,
     'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1);
 
     foreach 
($lookup as $roman => $value)
     {
         // Determine the number of matches
         $matches = intval($n / $value);
 
         
// Store that many characters
         $result .= str_repeat($roman, $matches);
 
         
// Substract that from the number
         $n = $n % $value;
     }
 
     
// The Roman numeral should be built, return it
     return $result;
 }


function smarty_rid($params, &$smarty) {
    $vars = $smarty->get_template_vars();
    return numberToRoman($vars['uid']);
}
 


Quick and certainly dirty - but it works as intended.

Cheerio!
arah
 
Posts: 4
Joined: Thu Nov 10, 2011 7:21 pm

Re: Archive List Configuration

Postby hansfn » Fri Nov 11, 2011 11:19 pm

Please never edit the core files - your changes will be lost when upgrading PivotX (which you'll have to do from time to time). Write an extension in stead - it's not much added code compared to what you have already written. (Just look at the hello world example.)
hansfn
Developer
 
Posts: 3072
Joined: Sun Nov 25, 2007 7:48 pm
Location: Molde, Norway

Re: Archive List Configuration

Postby arah » Sat Nov 12, 2011 5:25 pm

Okay, thanks for the tip! Will do.

Cheerio
arah
 
Posts: 4
Joined: Thu Nov 10, 2011 7:21 pm


Return to 2.x Support Forum

Who is online

Users browsing this forum: No registered users and 1 guest