Better Way to Backdate Blog Posts

Work harder not smarter...wait!

Posted by admin on May 05, 2023

I previously posted about how to backdate a blog post by adding a new field to the BlogPost content type and the overriding the views to take advantage of the new field. You can read about that here but DON'T DO IT THAT WAY!

Do it this way instead.

Root Cause

The default view for a blog post uses the content item's CreatedUtc property of ContentItem. If you can change this value then you can backdate your blog post.

And you can!

Common Part

Orchard Core ships with a collection of content parts - TitlePart, AutoroutePart, etc. You can read more about the available parts on the Orchard Core Documentation site.

In particular, the CommonPart provides the functionality to change the Date and Owner properties of the content item. For your BlogPost's CreatedUtc this is exactly the property you want to change.

Solution

Access the Admin UI and navigate to Content->Content Definitions->Content Types and click Blog Post to edit the BlogPost content type definition. Scroll down to the Parts section and click the Add Parts button. Then you can check the box next to Common and click the Save button.

This adds the Common Part to the Blog Post content type definition.

Next, upon save, you should've been redirect back to the Edit Content Type - Blog Post page where you can click the Edit button next to the Common part under the Parts section. Do that to see the Common Part settings where you should have two checkboxes for displaying the date editor and the owner editor.

Check the box next to the Display date editor setting which, as the hint next to it says, allows you to edit the create date of the conten item.

Click Save button and you're ready to back date your blog posts

Back date your Posts

Now, edit each one of your blog posts and find the Created input box which allows you to change the CreatedUtc to back date your post.

If you found value in this post, consider following me on X @davidpuplava for more valuable information about Game Dev, OrchardCore, C#/.NET and other topics.