Manaus Posted May 17, 2022 Share Posted May 17, 2022 I need to display the page https://www.mysite.com/article-2022-1-10/ when the https://www.mysite.com/latest-article/ url is entered. First url should stay hidden, no redirect. Just a content switch, keeping the same url as before. Thank you very much Link to comment Share on other sites More sharing options...
virtualgadjo Posted May 17, 2022 Share Posted May 17, 2022 hi, even it's a funny idea as - you'll be multiplying duplicate contents between this latest-article and... the latest article - the content of this latest-article will change quite often it's quite easy to achive, just use $pages->find with template and sort by -date (with your own field naming convention) to get the id of your latest article on top of the code and then use $pages->get(xxxx)->content and so on to display the latest article content/images/... in the page hope it helps have a nice day 3 Link to comment Share on other sites More sharing options...
Zeka Posted May 17, 2022 Share Posted May 17, 2022 As an option https://processwire.com/blog/posts/pw-3.0.173/#telling-processwire-what-page-to-render 2 Link to comment Share on other sites More sharing options...
ryan Posted May 17, 2022 Share Posted May 17, 2022 @Manaus This is a case where you should do a 302 redirect $session->location($article->url); rather than render different articles at the same URL. Otherwise folks won't be able to accurately bookmark it, and it'll confuse search engines, so it'd be an SEO problem. But I'll assume you know that and you want to do it anyway. What Zeka mentioned above is a good way to go, and probably the one I'd choose. But here's also another option below. It assumes you have a "latest-article" template and it is used by the page /latest-article/. /site/templates/latest-article.php $article = $pages->findOne("parent=/articles, sort=-created"); if(!$article->id) wire404(); echo $article->render(); If you are using prepend/append template files, then you'd also want to check the box to disable them in Setup > Templates > latest-article > Files (tab). 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now