Directory to Dates links
-
Hi,
I have directory in date format with files as date eg: /2015/04/15.pdf
I need to list the directory as year or month ?
-
I’m afraid I don’t understand your question.
I need to have Archive listing as date selection. As you guide is little hard to follow.
I have a report that i publish daily on my site, on a page which I show only the current month, all the previous I need to show as archive, So selection mechanism for the users to select a date or a month of a year (2009, 2013 etc) to get the files listed.I have the directory as following:
/PDF/Reprot-1/2015/04/15.pdf
Where the Report-1, is the directory of all the related reports
2015 – sub-directory of the year
04 – sub-directory of the month
15.pdf – file-name of the report as the date.
So I will be using the current month shortcode:
[fileaway type=”table” base=”2″ sub=”/4″ name=”April” search=”no” datelabel=”Updated” sortfirst=”mod” heading=”April”]After this I need a search box where the user enter the date to get the report listed.
Any reason why you don’t just do this?
Define Base 2 as:
PDF/Report-1
in your File Away settings page.
Then use this shortcode:
[fileaway directories=true base=2 search="no" datelabel="Updated" sortfirst="mod" heading="Archives"]
Thanks, Appreciate your support.
But its not sorting correctly, as my month folder are in Numeric, so its listing 1 (jan), 10 (oct), 11, 12, then 2 (feb), 3 …. so on.Can I have a search with date
I thing I am asking lot of question here, Sorry about that.
But Show can I remove the time from the date column, I need only the date without listing the time-stamp.
Also Is here a way to remove the file-name column, so I just have a PDF icon with the link.I highly recommend you rename your folders 01, 02, 03, 04, etc. All two-digits. It will solve your sorting problems, and is all-around a better policy.
There is no option to remove the time.
As an alternative, because I’m nice, I’ve created a class for you.
Remove your [fileaway] shortcode from the page, and replace it with this:
[fileaway_pdf_archives]
Then add the following code to your theme’s functions.php:
class my_fileaway_archives { public function __construct() { add_shortcode('fileaway_pdf_archives', array($this, 'router')); } public function router() { if(!isset($_REQUEST['fa_year']) || !isset($_REQUEST['fa_month'])) { $year = date('Y'); $month = date('m'); $heading = date('F, Y'); } else { $year = $_GET['fa_year']; $month = $_GET['fa_month']; $heading = date('F, Y', strtotime($year.'-'.$month.'-01')); } $files = do_shortcode('[fileaway type="table" base="2" sub="'.$year.'/'.$month.'" search="no" datelabel="Updated" sortfirst="mod" heading="'.$heading.'"]'); if(empty($files)) $files = 'No files found in this period.'; $archives = '<br><br>'; $archives .= '<h4>Archives</h4>'; $archives .= '<div id="archives-month-container" style="width:200px; margin-right:15px; display:inline-block;">'; $archives .= '<select id="archives-month-select" style="width:100%;">'; $months = array('01','02','03','04','05','06','07','08','09','10','11','12'); foreach($months as $m) $archives .= '<option value="'.$m.'" '.selected($month, $m, false).'>'.date('F', strtotime($year.'-'.$m.'-01')).'</option>'; $archives .= '</select>'; $archives .= '</div>'; $archives .= '<div id="archives-year-container" style="width:100px; margin-right:15px; display:inline-block;">'; $archives .= '<select id="archives-year-select" style="width:100%;">'; $now = date('Y'); foreach(range($now, 2009) as $years) $archives .= '<option value="'.$years.'" '.selected($year, $years, false).'>'.$years.'</option>'; $archives .= '</select>'; $archives .= '</div>'; $archives .= '<div id="archives-submit-button" style="width:40px; border:1px solid #888; background:#ECECEC; border-radius:4px; display:inline-block; padding:4px 10px; cursor:pointer;">Search</div>'; $script = "<script>"; $script .= "jQuery(document).ready(function($){ "; $script .= "$('body').on('click', 'div#archives-submit-button', function(){ "; $script .= "var year = $('select#archives-year-select').val(); "; $script .= "var month = $('select#archives-month-select').val(); "; $script .= "if(year == '' || month == ''){ alert('Please select a year and a month'); return false; } "; $url = fileaway_utility::querystring(get_permalink(), $_SERVER["QUERY_STRING"], array("fa_year" => "%y", "fa_month" => "%m")); $script .= "var url = '".$url."'; "; $script .= "url = url.replace('%y', year).replace('%m', month); "; $script .= "window.location.href = url; "; $script .= "}); "; $script .= "}); "; $script .= "</script>"; return $files.$archives.$script; } } new my_fileaway_archives;
Note: This, also, assumes your month directories are all two digits (01, 02, etc.)
Thanks alot, but Its just fixed for base=2.
and also its giving the following message:
“No files found in this period.”I should ask more and what I have got, but Do I have to add same code for all me bases that I want archives?
As I said above,
Define Base 2 as:
PDF/Report-1
And make sure all your month directories are 2 digits.
If you want to be able to have different base directories, do this:
Change this:
public function router() {
to this:
public function router($atts) { extract(shortcode_atts(array('base' => 1), $atts));
then change this:
$files = do_shortcode('[fileaway type="table" base="2" sub="'.$year.'/'.$month.'" search="no" datelabel="Updated" sortfirst="mod" heading="'.$heading.'"]');
to this:
$files = do_shortcode('[fileaway type="table" base="'.$base.'" sub="'.$year.'/'.$month.'" search="no" datelabel="Updated" sortfirst="mod" heading="'.$heading.'"]');
Then in your shortcode on the page, change it to this:
[fileaway_pdf_archives base=2]
Excellent. Thanks
I have noticed that I cannot increase the Base directory more than 5, so How can I overcome in the provided shortcode
[fileaway_pdf_archives base=2]
Can I use [fileaway_pdf_archives base=2 sub=Report-2]
Having the base changed from PDF/Report-1 to /PDF onlyWill that work?
You asked for a system where the user can choose the month and year from a dropdown, and have that populate the sub attribute. No such system existed in File Away, so I wrote one for you from scratch, and provided it to you freely. The sub attribute is populated by the year/month, exactly like you originally asked. Just so we’re clear, I’m creating a whole new system here, just for you.
Change this:
public function router($atts) { extract(shortcode_atts(array('base' => 1), $atts));
to this:
public function router($atts) { extract(shortcode_atts(array('base' => 1, 'report'=>''), $atts));
Then change this:
$files = do_shortcode('[fileaway type="table" base="'.$base.'" sub="'.$year.'/'.$month.'" search="no" datelabel="Updated" sortfirst="mod" heading="'.$heading.'"]');
to this:
$files = do_shortcode('[fileaway type="table" base="'.$base.'" sub="'.$report.'/'.$year.'/'.$month.'" search="no" datelabel="Updated" sortfirst="mod" heading="'.$heading.'"]');
Then in your shortcode, you’ll have to do this:
[fileaway_pdf_archives base=2 report="Report-2"]
Make sure you do not use forward slash there: just
report="Report-2"
. The forward slash is provided in the code.Also, in your base config, just set it to
PDF
(no forward slashes).That’s about all I’m able to do for you for free.
Thanks So Much, really saved my day, and all the diggings in google for the perfect file-manager.
This added all my archival requirements in just a single base directory.Your support is greatly appreciated!
If this gets approved, will surely buy the pro version (if it came out) or give a donation. ( can I have the link).
Hey ThomS,
How can I have the results below the Archive selection Submit button.
- The topic ‘Directory to Dates links’ is closed to new replies.