Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Home Page vs Date Based Archive Help
ps… I was just thinking that a lot could be achieved by allowing the use of forward slashes in the URL-only title
field in combination with a more thorough url detection system and associated tags… ie. the section tags could detect the 1st, 2nd… nth slash. I guess it’ll be like faking the sub-categories abstraction… just a thought.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Offline
Re: Home Page vs Date Based Archive Help
etc wrote #318098:
Ok, now
/2019/
is the year filter inyear/month/day/title
mode, but/year2019/
is a section URL. Additionally, all core clean modes recognize/section/title
URL.
Thanks Oleg. I’ve not tried it yet, but that sounds eminently sensible! Useful for blog or news sections where posts are fairly infrequent…
TXP Builders – finely-crafted code, design and txp
Offline
#16 2019-05-24 01:46:18
- dinoact
- New Member
- Registered: 2010-03-17
- Posts: 9
Re: Home Page vs Date Based Archive Help
Thanks for the replies all and sorry for my delayed response, work has been a bit crazy lately – it sounds like having a separate section for the archives and make use of mkp_url_parameters. I’ll play around a bit.
For my site, the url /2019/05/ works, but I want it to have a different behavior than the home page – I want the home page to limit to 1, but have the /2019/05/ mimic how I have my category archive pages – essentially creating monthly and category archive templates. Making the home page (which is treated as a an article list) and the /2019/05/ react differently is the part I’m having the most trouble with – again, I will play around with the above.
Also, sorry for opening a can of worms about custom functionality.
Offline
#17 2019-05-24 02:29:00
- dinoact
- New Member
- Registered: 2010-03-17
- Posts: 9
Re: Home Page vs Date Based Archive Help
Just had a thought and want to run it by the experts to see if anyone has done this before I test out:
Use txp:php to grab the $_SERVER[‘REQUEST_URI’], then parse that and use a couple different article_custom tags inside the php based on the parsing.
I know it’s not in the spirit of sticking to base functionality, but I think it would get me where I’m trying to go. I’m pretty comfortable with conditionals/regex/php.
Offline
Re: Home Page vs Date Based Archive Help
dinoact wrote #318194:
Just had a thought and want to run it by the experts to see if anyone has done this before …
I think you can achieve what you want much more easily.
Variant 1 – One page template for multiple uses (as mentioned here):
The default
page template is set up so that on the homepage you see the last 5 articles in full. But you can easily change the limit
attribute to 1
on this line to make it show just one article. If you want to display the homepage article in a special way, you can make your own article form and specify that in the form
attribute of the txp:article tag.
Variant 1a: The above template already has a means of detecting if you are on the homepage, but if you are rolling your own template, this snippet is a handy way of determining if you are on the homepage:
<txp:if_section name="default">
<txp:if_article_list type="author, c, month, pg, q" not>
<!-- this is the front page of the entire site -->
</txp:if_article_list>
</txp:if_section>
Variant 2 – Separate page templates for the homepage and archive sections
A really simple way of controlling the page output on different sections is just to create your own page template for the homepage section showing just the one article you want in the way you want to show it. Under Presentation › Sections you can then specify that the default section (that is the homepage) uses your new page template.
Date / year archives
The txp:article tag is contextually aware meaning that if you have an individual post, it will display just that article (default form: default, set your own with the form
attribute) and if you have a list page – i.e. the section landing page, or a page where the category, author or date filter is active – it will show a list of articles in short form (default form: article_listing, set your own with the listform
attribute) filtered automatically by the respective context.
Up to now, it responds automatically to /YYYY/MM/ urls. In a future version, thanks to etc, it will also respond automatically to /YYYY/ urls. You can already try that out now by downloading the dev version from Github. That may have your situation solved already.
dinoact wrote #318194:
Use txp:php to grab the $_SERVER[‘REQUEST_URI’], then parse that and use a couple different article_custom tags inside the php based on the parsing.
Just as background – as I don’t think you will need this – you can use txp:page_url with type="month"
to retrieve the context variable for the month value. If you need to or want to use some php, you can use variables as a bridge so you can return to regular txp tags, e.g. :
<txp:variable name="date_context"><txp:page_url type="month" /></txp:variable>
<txp:php>
global $variable; // required if you wish to get and set variables
$parts = explode("/", $variable['date_context']);
$variable['year_filter'] = $parts[0]; // year component
if (sizeof($parts)>1) {
$variable['month_filter'] = $parts[1]; // month component
}
// Format month component
if (!empty($variable['month_filter'])) {
$dt = DateTime::createFromFormat('!m', $parts[1]);
$variable['month_filter'] = $dt->format('F').' '; // month name plus space
}
</txp:php>
<p>Transporting you back to <txp:variable name="month_filter" /><txp:variable name="year_filter" />!
… and so on. If you use ?month=YYYY-MM
as a filter, you’ll need to replace the /
with -
above, i.e. $parts = explode("-", $variable['date_context']);
TXP Builders – finely-crafted code, design and txp
Offline
#19 2019-05-29 02:14:53
- dinoact
- New Member
- Registered: 2010-03-17
- Posts: 9
Re: Home Page vs Date Based Archive Help
Julian,
Thanks! I had no idea about type=“month” under both if_article_list and page_url. This should solve the issue. I should have researched more first, sorry.
Thanks a ton for your help. Sorry for the delayed reply again – remodeling the house while trying to fit time in to roll out another TXP site.
Last edited by dinoact (2019-05-29 02:17:07)
Offline