Show article end of publishing date and sort by that date?

Need help with the Administration of your Joomla! 2.5 site? This is the spot for you.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
aantickg
Joomla! Apprentice
Joomla! Apprentice
Posts: 37
Joined: Mon May 03, 2010 6:45 pm

Show article end of publishing date and sort by that date?

Post by aantickg » Sat Dec 22, 2012 12:44 pm

Hello,

I was wandering if it would be possible to modify core Joomla 2.5 files in order to display article end of publishing date in the category blog layout and to sort articles by that date?

Thanking you in advance!

 
User avatar
rcarey
Joomla! Explorer
Joomla! Explorer
Posts: 469
Joined: Sat Apr 25, 2009 9:20 pm
Location: Minnesota (USA)
Contact:

Re: Show article end of publishing date and sort by that dat

Post by rcarey » Sat Dec 22, 2012 1:39 pm

You can do both of these (show end date and sort by end date), and you can do it without editing the core files.

The following advice assumes that you are competent enough in php to understand existing code and to implement additions/changes.

The safe way to apply custom changes is to override the view file for the module or component. In this case, the files to override are found in

Code: Select all

/components/com_content/views/category/tmpl/
To display the end date, you will override blog_item.php (as this file contains the code that formats/displays the item. To change the sort order, it can be done in blog.php, but it might be more intuitive if you override blog_children.php, as this is the file that iterates through the items.

You will need to copy these two files and place them here:

Code: Select all

/templates/<current-template>/html/com_content/category/<files>
where <current-template> is the name of the template you have set as the default, and <files> represents the copied files to be pasted here (blog_item.php and blog_children.php). Further, you may need to add the directories /com_content/category/ if they are not already there.

The copied files that you just pasted are the ones to edit. They override the core files and will not be overwritten by core updates.

The easier change is to add the end date. You will need to look at the code to understand where each part of the article is being displayed, and then insert (where you want) the line that displays the end date. You will find examples in this file for displaying the create and published dates. The end date uses the field publish_down.

To reorder an array of items (in blog_childern.php), you can use the php function usort(). As you will see in this code, the array to be sorted is expressed as $this->children[$this->category->id]. The function usort() requires you to write a short comparison function that is passed into usort(), see discussion of this function here: http://php.net/manual/en/function.usort.php

Again, all this is doable without hacking the core files, and hacking the core files is a bad choice.
Randy Carey, the iCue Project http://iCueProject.com : developing an intelligent approach to improving the CMS user experience,
Careytech Studios http://careytech.com custom development for tailored or value-added web solutions

aantickg
Joomla! Apprentice
Joomla! Apprentice
Posts: 37
Joined: Mon May 03, 2010 6:45 pm

Re: Show article end of publishing date and sort by that dat

Post by aantickg » Thu Dec 27, 2012 11:24 am

Thank you very much for your answer! By following the procedure you gave me I was able to set the End publishing date to appear underneath the Start publishing date, but I did not manage to create the sort function. Would you be able to give me help by modifying the attached the blog-children.php file?
Thanking you in advance!
Aleksandar
You do not have the required permissions to view the files attached to this post.

User avatar
rcarey
Joomla! Explorer
Joomla! Explorer
Posts: 469
Joined: Sat Apr 25, 2009 9:20 pm
Location: Minnesota (USA)
Contact:

Re: Show article end of publishing date and sort by that dat

Post by rcarey » Thu Dec 27, 2012 10:57 pm

I'm glad you were able to leverage the first part of my suggestion.

I built out the second part for you, but then I realized that for a blog this technique will not do what I think you want it to. I have used this technique on other components/layouts, but in the case of the blog, the sorting needs to occur before the view file is called. That is because the blog layout presorts articles into multiple lists, so the sorting technique I suggested is limited per list and nor for the whole collection of articles within a category.

I do have an alternative solution to suggest. The simplest approach does require a one-line change to a core file, so the change can be lost upon a Joomla upgrade. But if the change is lost, the consequence is not terrible - the items would be sorted by the 'start' publish date instead of the 'end' publish date. Here is the suggestion...

Edit this core file

Code: Select all

/components/com_content/helpers/query.php
and go to line 135. You should see some text that forms part of the SQL query and includes two references to publish_up. change both of these references to publish_down. This changes the SQL query to return the articles sorted by the end date instead of the start date when sorting involves a published date.

Next, go to the menu item for the blog and set the Article Ordering to oldest first (or to most recent first). Then set the Date for Ordering to Published. It is the setting to Published that invokes the line of code you changed in the file query.php. And now that you changed it to use the end date instead of the start date, ordering should now occur on the end date.

There are two consequences to be aware of... [1] This change affects all modules and other uses of the Blog layout so that sorting by Published will now use the end date instead of the start date. [2] If an upgrade to a new Joomla version includes an updated version of the query.php file, then (until you re-apply your change) your change will be lost and sorting will occur on the start publishing date (but this other sort order is probably more of a nuisance than a major problem).

There is a way to avoid these two consequences, but it is more involved. In short, you would clone the category folder, create a new menu item type, and modify the code in view.html.php so that it managed the SQL query to your specific needs.
Randy Carey, the iCue Project http://iCueProject.com : developing an intelligent approach to improving the CMS user experience,
Careytech Studios http://careytech.com custom development for tailored or value-added web solutions

aantickg
Joomla! Apprentice
Joomla! Apprentice
Posts: 37
Joined: Mon May 03, 2010 6:45 pm

Re: Show article end of publishing date and sort by that dat

Post by aantickg » Tue Jan 08, 2013 1:02 pm

I apologize for the late response!
First of all, I would like to thank for your help and the solution. This is exactly what I needed and I believe your solution will help many others trying to order articles by the end publishing date! So by this procedure, I enabled my client to enter new articles from the front end which are then ordered by the end publishing date. When this date expires the article disappears from the front end, but what concerns me is why the articles are still published in the back end? Would you be able to help me with this too?
Thanking you in advance!
Aleksandar

User avatar
rcarey
Joomla! Explorer
Joomla! Explorer
Posts: 469
Joined: Sat Apr 25, 2009 9:20 pm
Location: Minnesota (USA)
Contact:

Re: Show article end of publishing date and sort by that dat

Post by rcarey » Tue Jan 08, 2013 3:16 pm

Thanks for letting me know that my suggestion accomplished your objectives. I appreciate the feedback.

Regarding the expired articles still showing in the backend… this is standard Joomla behavior. When an article expires, its state (published, unpublished, archived, trashed) does not change.

If you want a published article that is expired to automatically change its state from published to archived (or to trashed), then I recommend you write a cron job that runs periodically (daily? hourly?) that will run an SQL query to find such articles and then change the state accordingly.

I know a code solution for not showing expired articles in the backend’s list of articles, but the problem is that when you stop showing them here, you no longer have the ability to edit them (such as to change the state to archive, or to extend the end date for publishing). You would want to have expired articles still visibly listed to users belonging to special user groups (admin, super admin, or something like that). That can be coded, but it has to be coded for the specifics of your needs (which user groups can see expired articles, which cannot).

Does that give you enough information to do what you want?
Randy Carey, the iCue Project http://iCueProject.com : developing an intelligent approach to improving the CMS user experience,
Careytech Studios http://careytech.com custom development for tailored or value-added web solutions

aantickg
Joomla! Apprentice
Joomla! Apprentice
Posts: 37
Joined: Mon May 03, 2010 6:45 pm

Re: Show article end of publishing date and sort by that dat

Post by aantickg » Tue Jan 15, 2013 12:04 pm

Thanks for your reply and again sorry for the late response. In my situation the expired articles are not needed at all. Actually these are electronic ads that my client wants to delete after they expire and a good solution would be if this process could be automatic. I am not really sure how to create a cron job but I will surely give it a try. Do you have any other suggestion based on the process I explained?
Thanking you in advance!
Aleksandar
The url for my website is: http://ja.os.sud.rs/home/elektronska-og ... na-imovina

User avatar
rcarey
Joomla! Explorer
Joomla! Explorer
Posts: 469
Joined: Sat Apr 25, 2009 9:20 pm
Location: Minnesota (USA)
Contact:

Re: Show article end of publishing date and sort by that dat

Post by rcarey » Tue Jan 15, 2013 3:38 pm

The first step in automating this is to build or obtain some code that performs the task you want done - finding expired items and changing their state (or deleting them). That process can be coded, or perhaps there is an available plugin that does this.

The second step is to set up a process that triggers this code. That could be a cron job (that automatically runs every so often), but it could also be a quick maintenance step that you assign to the site admin (such as clicking a button to run the process).

If you can't find a pre-built solution and can wait a bit, PM me. I see value in developing a plugin to manage expired items, so I might add it to my list of extensions to build.
Randy Carey, the iCue Project http://iCueProject.com : developing an intelligent approach to improving the CMS user experience,
Careytech Studios http://careytech.com custom development for tailored or value-added web solutions

aantickg
Joomla! Apprentice
Joomla! Apprentice
Posts: 37
Joined: Mon May 03, 2010 6:45 pm

Re: Show article end of publishing date and sort by that dat

Post by aantickg » Tue Jan 15, 2013 8:03 pm

Ha ha! You are great! Thank you in advance! I can wait as long as you do not forget about it :) Best regards!

starlingsnest
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Tue Jun 01, 2010 10:30 am

Re: Show article end of publishing date and sort by that dat

Post by starlingsnest » Wed Nov 27, 2013 9:13 pm

I too need both start and end dates to be available and copied the file 'blog_item.php' to the template as directed but cannot now find anything about start, create or publish dates in the php file other than where it says "('show_create_date')" etc. Is there not by now a plugin to provide start and end dates? I notice that Joomla 3.0 has gone back to providing these.

 

Locked

Return to “Administration Joomla! 2.5”