Make most recent post blog the main blog.

Dcode warner asked on March 28, 2017 23:41

How can I make the most recent blog post ALWAYS be the default landing page of the blog ("/blog")?

Basically, we want to make an 'Archive' page which is just a list of all the blog posts. The easiest solution I think to do so, is make the entire blog the "Archive" and the latest blog post the home page.

Correct Answer

Peter Mogilnitski answered on March 29, 2017 20:11

If properties/navigation/Menu Actions/Navigation URL doesn't work for some reason you can use Random Redirection web part. Add this web part to your main blog page and put the same macro in the Redirection URLs:
{%CurrentDocument.Children.FirstItem.Children.FirstItem.AbsoluteURL|(identity)GlobalAdministrator%}.

Because there is only 1 item available in the list - it will always redirect to this item.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Trevor Fayas answered on March 29, 2017 04:11

Very simple. Use a Repeater of Blog Post objects, order by the BlogPostDate Desc, and select the Top 1

This will be your most recent blog :)

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on March 29, 2017 16:52 (last edited on March 29, 2017 17:43)

[updated] This is pointing me into the right directions. Now I need to make an archive page or have the blog with the post snippets move to a new URL

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on March 29, 2017 18:09 (last edited on March 29, 2017 18:11)

Yup, keep in mind of course you can have multiple repeaters on a page, so you could have 1 repeater that only selects the most recent blog, and shows the full blog content, and another repeater below it that shows all the rest with only a "preview" of the blog article

Keep in mind if you want exclude the most recent one from your archive listing below, you will need to use the WHERE condition to exclude it (such as WHERE: BlogPostID <> (Select top 1 BlogPostID from CONTENT_BlogPost order by BlogPostDate desc)), but this wouldn't take into account the PUBLISH setting, in which case it may be better to, in the transformation, just hide the first (which will be the most recent blog post): <div class="<%# If(IsFirst(), "hidden", "") %>">...TheBlogSummaryHere...</div>

If you want to make a single url redirect to the actual blog page itself, then you would need to (on that url) use the Random Redirect web part, and use a macro for the value to get the Node Alias Path of the most recent blog article, so the user visiting the url gets redirected to the most recent blog post. A bit more advanced though.

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on March 29, 2017 19:14

It also depends on your site structure. Take a look at main blog page properties/navigation/Menu Actions: "Redirect to first child" and "URL redirection". If your main blog page has children and the first is the latest blog post, you can use the fist option. Or you can create a custom macro {%GetLatestPostURL%} and put it into URL redirection

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on March 29, 2017 19:47 (last edited on December 10, 2019 02:30)

@PeterM I have Kentico 7 I see "URL Redirection" but not "Redirect to first child" (sounds very useful)

This macro points to the month: "/Blog/March-2017" {%Documents[NodeAliasPath].Children[0].NodeAliasPath|(identity)GlobalAdministrator%}

How do I get the child?

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on March 29, 2017 19:48

@Trevor Fayas I'm having troubling understanding, making the two URLS to display the content from the two repeaters.

Do I need to create a new page / templates?

Maybe using the Random Redirect web part will be better but Im not that advance in writing a macro that can do this redirect function to the recent blog post.

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on March 29, 2017 20:01 (last edited on December 10, 2019 02:30)

Looks a bit complex, my guess is you have blog/month/blogpost structure You need to go deeper on leverl in your macro {% CurrentDocument.Children.FirstItem.Children.FirstItem.AbsoluteURL |(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on March 29, 2017 20:22 (last edited on December 10, 2019 02:30)

@Peter M I tried both ways in the web part. Both redirect me to the home page :(

Im placing the code here. Is this correct? http://prntscr.com/eq0nnw

[udpated] This works in the marco: {%Documents[NodeAliasPath].Children[0].NodeAliasPath|(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on March 29, 2017 20:29

I just learned a new print screen sharing site, thanks Dcode!

Are you getting it, or still having problems now?

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on March 29, 2017 20:37 (last edited on December 10, 2019 02:30)

@Tevor Fayas. Your welcome, been using it for a year. It nice storing images in the cloud.

Still having problems. Using the Random Redirect what @Peter M suggestedt. However the coding it's quite right.

  • {%Documents[NodeAliasPath].Children[0].NodeAliasPath|(identity)GlobalAdministrator%} redirects to home page of website

Almost there, just trying to point /blog to the most recent url.

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on March 29, 2017 20:45 (last edited on December 10, 2019 02:30)

Seems Ok. As you see the macro is relative to page.Image Text

If you are on the main blog page which is "Holiday in Australia" and you place macro:

{%CurrentDocument.AbsoluteURL|(identity)GlobalAdministrator%} gives you URL for Flying Tomorrow.

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on March 29, 2017 21:04 (last edited on December 10, 2019 02:30)

@Peter M I understand. Unfortunately, still giving the same results as before.

{%CurrentDocument.Children.FirstItem.Children.FirstItem.AbsoluteURL|(identity)GlobalAdministrator%} redirects to the main home page. Do you think it's K7 version the reason?

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on March 29, 2017 21:11

No. 7 is fine. Especially for a simple macros like that. Can you put the macro in static text web part and add this web part to your main blog page - just to make sure that it returns the right URL?

I've done this test on Community sample site and it was OK.

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on March 29, 2017 22:13 (last edited on December 10, 2019 02:30)

Alright. I did a simple test. [updated]

The results:

http://prntscr.com/eq2bbz http://prntscr.com/eq2bpt

{%CurrentDocument.AbsoluteURL|(identity)GlobalAdministrator%} - returns nothing

So how come it doesn't work in the random redirect webpart?

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on March 30, 2017 01:14 (last edited on December 10, 2019 02:30)

Random redirect - redirects to the home page because {%CurrentDocument.Children.FirstItem.Children.FirstItem.AbsoluteURL|(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on March 30, 2017 17:39 (last edited on December 10, 2019 02:30)

{%CurrentDocument.Children.FirstItem.AbsoluteURL|(identity)GlobalAdministrator%}? Do you know how I can write that?

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on March 30, 2017 20:07

Okay. I was able to figure it out. It was on my error. We have a two sites. One LIVE and the other not.So the path was going to the LIVE site. Just debugging. Updating the path and placing it into the random redirection works.

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on June 22, 2017 22:43 (last edited on December 10, 2019 02:31)

I figured it out. To make it the last item of the blog. You have to change to:

{%CurrentDocument.Children.FirstItem.Children.LastItem.AbsoluteURL|(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.