0

I created a view which summarise the nodes and displays them in a year + month block. The result looks like this:

március 2015 (26) 
február 2015 (12)
január 2015 (18)

I'd like to change the date format according to Hungarian standards:

2015 március (26) 
2015 február (12)
2015 január (18)

I tried to find the appropriate settings in date/time settings (admin/config/regional/date-time) without any success.

1

Create a template file of your view Display output: views-view--view-post-by-date--block.tpl.php

Make some slight changes where row is printing in your tempalate file:

         <?php if ($rows): ?>
        <div class="view-content">
         <?php 
   $output = '';
 for($i=0;$i<5;$i++){
$filter_link = date("Ym",strtotime("-$i months"));
$filter_display = date("Y F",strtotime("-$i months"));
$link = $GLOBALS['base_url'].'/post-by-date/'.$filter_link;
 $output .= '<a href="'.$link.'">'.$filter_display.'</a>('.count($filter_display).')<br>';

  }
print $output;
// print $rows; ?>

 </div>
  • Unfortunately it isn't the solution I need: As far as I see your code creates a monotone list of months (without the correct count of news items) instead of the list of months actually have any news. Meanwhile I managed to figure out a more suitable solution - see below. – StG Feb 1 '16 at 16:36
0

You can create your own date formats at admin/config/regional/date-time/formats.

If you have the locale module enabled, you can localize your formats at admin/config/regional/date-time/locale.

Once you've created your own date format, you can tell views which format should be used to render a date.

0

To change the date from "március 2015" to "2015 március", you can follow the following steps:

  • Go to path "admin/config/regional/date-time/formats"
  • Click on "Add Format"
  • In "Format string" field, add "Y F"
  • Now go to path "admin/config/regional/date-time" and change the format for your date-type.

Please try this, it will solve your problem.

  • :( ...........this one not working – user52318 Jan 14 '16 at 10:20
0

For changing the date format in summary of months, I had to create a custom template of views-view-summary-unformatted.tpl.php, lets call it views-view-summary-unformatted--post-by-date--block-1.tpl.php and place it in the templates folder of my theme. In this template we can find $row->link variable which is need to be replaced with the correct value. For this sake I processed the $row->created_year_month varible as follows:

<?php
    $archive_year = substr($row->created_year_month, 0, 4);
    $archive_month = substr($row->created_year_month, 4, 2);
    $archive_timestamp = mktime(0, 0, 0, $archive_month, 1, $archive_year);
    $archive_date = format_date($archive_timestamp, 'custom', 'Y. F');
?>

Finally I replaced the $row->link with $archive_date.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.