Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
2 posts Page 1 of 1
Someone recently asked me if it was possible to customize the 'publish date' field shown in the 'Advanced settings' dropdown of admin-panel edit screen (wanted to show the day first followed by month and then year; also the months needed to be shown in a different language).

Those of us familiar with the customization features of v2.0 of course know that it is. In fact, the official v2.0 thread viewtopic.php?f=5&t=10241 has an example where we try to create a custom field somewhat mimicking the system publish-date field.

However to make it even easier for the client to do that by himself, I sent a ready-to-implement solution that does this job with more fidelity. I think this solution could be helpful to others looking for a quick solution to this problem so I am pasting my reply here in full.

===============================================================================================

If the default display of the publish-date does not suit you, we can replace it with a custom field of our own.

In case you have come across the following thread, you'll find that the admin-panel allows pretty extensive customization -
viewtopic.php?f=5&t=10241

In the mentioned thread, under the topic 'Customizing the Form screen', you'll find a discussion on adding custom fields to the form.
An example there shows creating a field that looks and works like the system publish-date field.

To make things easier for you, here is an adaptation of it that mimics the system field more closely -
Code: Select all
<cms:config_form_view>
    <cms:persist
        k_publish_date="<cms:if frm_my_publish_status='0'>0000-00-00 00:00:00<cms:else/><cms:show frm_my_publish_date /></cms:if>"
    />

    <cms:field 'my_publish_status' label='Publish Date' order='100' group='_advanced_settings_'>
        <cms:input type='radio'
              name=k_field_input_name
              opt_selected="<cms:if k_page_date='0000-00-00 00:00:00' >0<cms:else />1</cms:if>"
              opt_values='Published=1 | Unpublished=0'
            />
           
        <div id="my-date-dropdown" style="<cms:if k_page_date='0000-00-00 00:00:00' >display:none;</cms:if>">
            <cms:input
                name='my_publish_date'
                label='Publish Date'
                type='datetime'
                format='mdy'
                allow_time='1'
                minute_steps='1'
                fields_separator='.'
                default_time="<cms:if k_cur_form_mode='edit' && k_page_date!='0000-00-00 00:00:00'><cms:show k_page_date /><cms:else />@current</cms:if>"
                required='1'
            />
        </div>   
    </cms:field>

    <!-- hide the original publish-date field -->
    <cms:field 'k_publish_date' hide='0'  />

    <cms:script>
        $( function(){
            $('#my_publish_status1').on('click', function(e){
                $('#my-date-dropdown').css('display', 'none')
            });
            $('#my_publish_status0').on('click', function(e){
                $('#my-date-dropdown').css('display', 'block')
            });
        });
    </cms:script>
   
    <cms:style>
        #my-date-dropdown .dt_month+.dt_sep{display:none;}
        #my-date-dropdown .dt_month{margin-right:12px;}
        #my-date-dropdown .dt_day input{max-width: 50px; text-align: center;}
        #my-date-dropdown .dt_year input{max-width: 62px; text-align: center;}
    </cms:style>
</cms:config_form_view>

Please place the code above within the <cms:template> block of one of your your templates (once you are done testing and wish to place it in multiple templates, move the code into a snippet and then you can use <cms:embed> to include it in multiple templates).

Visit the template on the frontend as super-admin. Coming back to the admin panel, you should find a new publish-date field right below the system field in 'Advanced settings' dropdown.

untitled.png
untitled.png (18.68 KiB) Viewed 2736 times


Try setting a new date in it or select unpublish from it and, upon saving the page, you should find that its value gets reflected in the system date field.

Once you are assured of that, we can go ahead and hide the system date field thus leaving our custom field in its place.
To do that, set the following line in the provided code above to '1' -
Code: Select all
    <!-- hide the original publish-date field -->
    <cms:field 'k_publish_date' hide='1'  />

Using our custom field makes it possible to customize it in whatever way you desire.
Since it is built using the type 'datetime' editable region (discussed here - viewtopic.php?p=12667#p12667), you may set the month names in the language of your choice and also select 'dmy', 'ymd' or 'mdy' as the display.

Hope this helps.

Thank you a lot! This was very very helpful! :)
2 posts Page 1 of 1