Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
same URL-only title and article status
I have two articles with the same URL-only title. One is live, the other is set to go live at a future date. The one that is live will expire when the second one goes live. However, only the future article gets displayed. Using <txp:article status="live" /> has no effect. Help would be much appreciated.
Offline
Re: same URL-only title and article status
If you’re using one of the no-ID permanent link modes (e.g. /section/title) then I think you will always get the first article (of the two with the same title) in the database. I’m guessing this is the one with the lower ID number. And I don’t think you’d solve the problem by switching the articles, because after the expiration date you would then have the opposite problem.
Code is topiary
Offline
Re: same URL-only title and article status
Isn’t this a bug then?
TXPDream – A Textpattern Tag Library for Adobe Dreamweaver. (updated for 4.2.0) | jdw_if_ajax – Only serve certain parts of a page when requested with AJAX
Offline
Re: same URL-only title and article status
I don’t think so. If you opt to use the /section/title or /title URL scheme, you need to use distinct URL-only titles. Stands to reason.
Code is topiary
Offline
#5 2010-06-24 20:06:35
- els
- Moderator

- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: same URL-only title and article status
Does it work if you explicitly add time="past"?
Offline
Re: same URL-only title and article status
Stands to reason.
Ah, somehow I missed the ‘same URI-title’ thing…
Just an idea: since you can use txp tags in an article I suppose you could pull in that article (and its replacement) with article_custom from another section (maybe just created for these articles) so that you can have two different URI-titles ?
Last edited by JanDW (2010-06-24 20:56:30)
TXPDream – A Textpattern Tag Library for Adobe Dreamweaver. (updated for 4.2.0) | jdw_if_ajax – Only serve certain parts of a page when requested with AJAX
Offline
Re: same URL-only title and article status
I take the point about same url_title and IDs not being a bug. However, it seems a bit flawed if publish dates are explicity ignored. Using time="past" has no effect. I’ll try the article_custom method suggest by JanDW.
Offline
#8 2010-06-25 12:34:17
- els
- Moderator

- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: same URL-only title and article status
ricetxp wrote:
One is live, the other is set to go live at a future date. The one that is live will expire when the second one goes live.
Does this mean that the article that has the future date actually has a status other than ‘live’?
Offline
Re: same URL-only title and article status
ricetxp:
You may want to take advantage of txp:if_expired, and use it directly in your article body.
<txp:if_expired>
future content, blabla
<txp:else />
current content
</txp:if_expired>
Offline
Re: same URL-only title and article status
@Julián: Nice idea but my guess is that it still won’t work. The lookupByTitle() function (see publish.php) simply looks for the first matching article by url-only title that has live status. If there are two articles with the same title I expect it will always return the same one.
@Edward: I don’t disagree that this is a flaw (although I would use the word “limitation” instead). Simplest solution is to use IDs in the URL. I can well understand that this is not ideal, especially if this is an established site. Other workarounds are possible; what is best (or least bad) would depend on the exact requirements and characteristics: are there many articles you want to treat this way, if so is there an easy way to distinguish these from other articles, etc.
Code is topiary
Offline
Re: same URL-only title and article status
At present it’s a one-off. I’ve decided to do the change over manually. I’ve given the future article (status="live") a different url_title for the time being. On the day of change over, I’ll manually change the url_title and hide the expired article.
The article was for a competition. The idea is to promote it before it goes live. Hence the need to keep the same url. There’s quite bit of competition logic which isn’t on the article itself, but is called in with custom_field values, so it makes it difficult to try and use a different method.
I love textpattern, but I guess I was simply expecting not to see articles that were set with a future publish date to be live on the site, regardless of other overriding logic.
Offline
Re: same URL-only title and article status
Jeff: my idea implied discarding one of the two same URL-only title articles, and do all the switch inside the article body, with the help of txp:if_expired.
Regarding a solution for the original setup (two articles, both set to “live”, one is currently “past” and set to expire, the other is just set to a “future” date, both sharing the same URL-only title): although I don’t know exactly how the inner cogs of TXP works (jsoo gave some insights on this thread about this), I wonder if this couldn’t just be solved by a clever/basic usage of txp:article or txp:article_custom and its attributes.
Mmmm… now that I think a bit more about this, I’m now assuming this is not a problem in an article list context, but on the individual article (aka permalink) context, correct?
I mean, on article list context it may or may not be issues for having two articles with the same URL-only title, but when on individual article, TXP necessarily fetchs it from database using the lookupByTitle, as Jeff mentioned.
As Jeff clearly stated, the best solution will depend on the exact requirements. If this is just an edge case, you could just do some article ID hardcoding somewhere in your templates to solve this easily.
Offline
Re: same URL-only title and article status
ricetxp wrote:
The article was for a competition.
Just as an aside, the smd_countdown plugin might help here.
I kind of understand why you might want two articles — pre and post event — but I don’t think there’s much need unless you don’t want your authors to see tags in the article Body. I may have missed something in the above discussion, though.
How about using the ‘else’ part of smd_countdown to display the info for before the event, set the expiry of the article as maniqui suggests (and allow expired articles to be published in Advanced Prefs) and then use the ‘true’ branch of smd_countdown to display different information once the article expiry is reached:
<txp:smd_countdown to="expires">
Sorry, competition closed.
<txp:else />
Hurry, hurry and get your entries in. You only have <txp:smd_time_info display="day_total"> days left!
</txp:smd_countdown>
EDIT: if_expired would allow you to do the same sort of thing without the handy countdown…
Last edited by Bloke (2010-06-25 16:47:05)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: same URL-only title and article status
@Steff smd_countdown has worked a treat. FYI this is how I’m using it in an article form:
<h2><txp:title /></h2>
<div class="content offer offer-<txp:article_url_title />">
<txp:if_custom_field name="pre-release">
<txp:smd_countdown to="?pre-release">
<txp:php>
...competition logic...
</txp:php>
<txp:else />
<txp:body />
</txp:smd_countdown>
<txp:else />
<txp:php>
...competition logic...
</txp:php>
</txp:if_custom_field>
</div>
Thanks everyone for all the help.
Offline