Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: txp:article_custom via php echo
uli wrote #306746:
Could you describe a little what you want to achieve and why you think the best way to do this is via article URL? Maybe someone could offer some other way to solve it. E.g. if you want to use a URL parameter to call an article, then you might want to have a look at adi_gps.
Hi. Well, i think using article_id is better than article_url. Therefore my question is not important anymore. Furtheremore, i have solved it through a custom_field, but still article_id is better.
What i wanted to achieve is to use parent and children articles using categories with the same urls as those of articles. But I have found that naming a category as article_id is more convinient. Something like here
The code example with article_id
<ul class="Parent-Articles">
<txp:article_custom section="your-section" limit="999">
<li><txp:permlink><txp:title /></txp:permlink></li> <!-- list of parent articles -- >
<ul class="Child-Articles"><!-- list of child articles if category name is the same as parent artilce's ID. If not, nothing will be displayed -- >
<txp:article_custom category='<txp:article_id' limit="999">
<li><txp:permlink><txp:title /></txp:permlink></li>
</txp:article_custom>
</ul>
</txp:article_custom>
</ul>
Last edited by zenman (2017-08-29 07:02:03)
Offline
Re: txp:article_custom via php echo
Yes, that could work. Your example from that site has a small syntax error (missing closing tag for <txp:article_id />) and produces invalid HTML (for the nested ul-lists). It can also be made more succinct by including wraptag, class, and break attributes in your article_custom tag. That way nothing is shown if there are no relevant articles (in the above example, you get an empty <ul></ul> for every article without sub-articles).
However, even with the changes below, I think you may run into the problem that the child articles (if they are also in the section your-section) will be listed twice in the output, once as a child-article and once in the main list. You’ve no way of excluding the child articles from the main list. To achieve that you would need to put the child articles in another section.
<!-- list of parent articles -->
<txp:article_custom section="your-section" limit="999" wraptag="ul" class="Parent-Articles" break="li">
<txp:permlink><txp:title /></txp:permlink>
<!-- list of child articles if category name is the same as parent article's ID. If not, nothing will be displayed -->
<txp:article_custom category='<txp:article_id />' limit="999" wraptag="ul" class="Child-Articles" break="li">
<txp:permlink><txp:title /></txp:permlink>
</txp:article_custom>
</txp:article_custom>
The classical way to achieve the pattern shown in that article is to use sections and articles.
About [section] – Parent article [sticky]
Services [section] – Parent article [sticky]
service 1 – child article [live]
service 2 – child article [live]
service 3 – child article [live]
Contact [section] – parent article [sticky]
Rather than using categories, create a section for each menu item, e.g. here “about, services, contact” and assign articles to each section. For the top-level landing page, set the article status to “sticky”, the sub-articles to “live”.
<!-- main sections menu -->
<txp:section_list sections="about,services,contact" wraptag="ul" class="parent-sections" active_class="active" break="li">
<txp:section link="1" title="1" />
<!-- articles in <txp:section /> section -->
<txp:article_custom section='<txp:section />' limit="999" wraptag="ul" class="child-articles" break="li">
<txp:permlink><txp:title /></txp:permlink>
</txp:article_custom>
</txp:section_list>
Then, on your template for each section use txp:article with status="sticky" to display the landing-page article.
You only need the parent/category way, if you need a third tier, i.e. you are already using sections and need parent/child articles within one section. And if that is what you do need, you might find parent/child categories a more effective way of avoiding double article output.
TXP Builders – finely-crafted code, design and txp
Offline
Re: txp:article_custom via php echo
jakob wrote #306754:
Yes, that could work. Your example from that site has a small syntax error (missing closing tag for
<txp:article_id />) and produces invalid HTML (for the nested ul-lists). It can also be made more succinct by includingwraptag,class, andbreakattributes in your article_custom tag. That way nothing is shown if there are no relevant articles (in the above example, you get an empty<ul></ul>for every article without sub-articles).However, even with the changes below, I think you may run into the problem that the child articles (if they are also in the section your-section) will be listed twice in the output, once as a child-article and once in the main list. You’ve no way of excluding the child articles from the main list. To achieve that you would need to put the child articles in another section.
<!-- list of parent articles -->...The classical way to achieve the pattern shown in that article is to use sections and articles.
About [section] – Parent article [sticky]...Rather than using categories, create a section for each menu item, e.g. here “about, services, contact” and assign articles to each section. For the top-level landing page, set the article status to “sticky”, the sub-articles to “live”.
<!-- main sections menu -->...Then, on your template for each section use
txp:articlewithstatus="sticky"to display the landing-page article.You only need the parent/category way, if you need a third tier, i.e. you are already using sections and need parent/child articles within one section. And if that is what you do need, you might find parent/child categories a more effective way of avoiding double article output.
Thanks for noticing syntax error, in real time textpattern would show that. Sections are ok if you use four or five like about, articles, contact, etc.
Managing too many sections with two or three child articles is not always very convinient. Then what if one needs several subsection with just a couple of child articles? Does it make any sense to create so many of them? With article_id categories it is much easier to administer articles.
One can easily exclude child articles from the main list by adding parent articles to a separate category.
Example (sorry, it is not in English but the idea is understandible): http://cargoalliance.ru/geo/
Parent articles are with flags and their child articles are below under article_id category. I think using so many sections with flags instead of articles would be too tiresome.
I tried to connect articles and categories with url but realised that article_id was a better decision because I can see ids right in the lilst without opening them.
Offline
#19 2017-08-29 20:47:17
- uli
- Moderator

- From: Cologne
- Registered: 2006-08-15
- Posts: 4,319
Re: txp:article_custom via php echo
Hi zenman, the email link has a typo (lacks 1 small L). That’s the stuff my attention springs at ;)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
#20 2017-08-29 22:23:44
- makss
- Plugin Author
- From: Ukraine
- Registered: 2008-10-21
- Posts: 355
Re: txp:article_custom via php echo
zenman, You can create categories with the same names as the url_title of the parent articles.
For example, a category tree can be:
country china hongkong europe ...
- All parent articles has
category= “country”- First parent article has
url_title= “china” - Second
url_title= “hongkong” - …
url_title= “europe”
- First parent article has
- Child articles have one of the categories: “china”, “hongkong”, “europe”. And have any
url_title.
A slightly modified jakob code.
<!-- list of parent articles -->
<txp:article_custom category="country" limit="999" wraptag="ul" class="Parent-Articles" break="li">
<txp:permlink><txp:title /></txp:permlink>
<!-- list of child articles if category name is the same as parent url_title. If not, nothing will be displayed -->
<txp:article_custom category='<txp:article_url_title />' limit="999" wraptag="ul" class="Child-Articles" break="li">
<txp:permlink><txp:title /></txp:permlink>
</txp:article_custom>
</txp:article_custom>
On one of my projects, I used a similar approach.
aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)
Offline
Re: txp:article_custom via php echo
uli wrote #306778:
Hi zenman, the email link has a typo (lacks 1 small L). That’s the stuff my attention springs at ;)
ahh, yes, that’s just a test, not working site. (as a matter of fact there is no such a domain email in reality) emails, phones and everything else will be different.
Offline
Re: txp:article_custom via php echo
makss wrote #306779:
zenman, You can create categories with the same names as the
url_titleof the parent articles.For example, a category tree can be:
country...
- All parent articles has
category= “country”
- First parent article has
url_title= “china”- Second
url_title= “hongkong”- …
url_title= “europe”- Child articles have one of the categories: “china”, “hongkong”, “europe”. And have any
url_title.
A slightly modified jakob code.
<!-- list of parent articles -->...On one of my projects, I used a similar approach.
Possible. But in breadcrumbs it will be problematic to display parent article by its url. That’s why I started this topic. Then I had to go back to article_ids: (Displays as many levels as one needs if copy that piece of code starting with <txp:if_article_category>… and paste in the right place)
<txp:breadcrumb label="Homepage" link="1" separator=" » " title="1" wraptag="" />
<txp:if_article_category>
<txp:article_custom id='<txp:category1 />'>
<txp:if_article_category>
<txp:article_custom id='<txp:category1 />'>
» <txp:permlink><span><txp:custom_field name="info_1" /></span></txp:permlink>
</txp:article_custom>
</txp:if_article_category>
» <txp:permlink><span><txp:custom_field name="info_1" /></span></txp:permlink>
</txp:article_custom>
</txp:if_article_category>
Bread crumb example: http://cargoalliance.ru/china_lcl_phones where » Direction is the section » China is a parent article » LCL is a child of China and china_lcl_phones is a child of LCL.
Last edited by zenman (2017-08-30 17:21:16)
Offline
Re: txp:article_custom via php echo
Hi zenman,
I see a couple of problems with your code
- breadcrumb tag is not closed
<txp:article_custom id='<txp:category1 />'>did you give numbers to the categories? What happens if somebody uses the same category for 2 articles?
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: txp:article_custom via php echo
colak wrote #306784:
Hi zenman,
I see a couple of problems with your code
- breadcrumb tag is not closed
<txp:article_custom id='<txp:category1 />'>did you give numbers to the categories? What happens if somebody uses the same category for 2 articles?
1. yes. sorry. I type / copy / paste in a hurry and my English is a little rusty so I can make some misprints. I hope txp people understand what is suppposed to be there and I have already closed the tag.
2. yes, I name categories by article_id like 2, 3, 4… if somebody uses the same category for 2 or 3 or 4, 5 articles then there will be two child articles of article 3, 4 or whatever. See http://cargoalliance.ru/geo/ The first article in the list (China) has several children. Or did I misunderstand something?
That may be not ideal but to me it looks more easy-to-administer than messing with 30 sections for 30 countries.
The idea with category url = article url is good. But I stumbled over breadcrumbs with it. And one more thing, you cannot see an article url without opening it which takes some time. How do you know where the parent China article is if there is several articles with China in the title, for example. You have to open it and look at its url. But to see an article id is easier because they are listed one by one in the Articles panel.
Last edited by zenman (2017-08-30 18:04:12)
Offline
Re: txp:article_custom via php echo
zenman wrote #306785:
The idea with category url = article url is good. But I stumbled over breadcrumbs with it. And one more thing, you cannot see an article url without opening it which takes some time. How do you know where the parent China article is if there is several articles with China in the title, for example. You have to open it and look at its url. But to see an article id is easier because they are listed one by one in the Articles panel.
Performance-wise, ID is better than url because it’s a primary index of textpattern table. Nevertheless, the whole ID=Category1 thing feels wrong. In 4.7 <txp:breadcrumb /> is more flexible and categories could suffice for your needs. If you can wait, of course :-)
Offline
Re: txp:article_custom via php echo
etc wrote #306797:
Performance-wise,
IDis better thanurlbecause it’s a primary index oftextpatterntable. Nevertheless, the wholeID=Category1thing feels wrong. In 4.7<txp:breadcrumb />is more flexible and categories could suffice for your needs. If you can wait, of course :-)
can’t wait to see. will categories suffice for the whole parent-child issue dusscussed here or just <txp:breadcrumb /> part ?
i usually use categories for admin purposes to sort out articles – featured, children, homepage. they are not indexed by google and not accessible by front-end users unless it is a standard blog.
Last edited by zenman (2017-08-31 15:08:19)
Offline
Re: txp:article_custom via php echo
I would follow this:
makss wrote #306779:
For example, a category tree can be:
country
china
lcl
...
hongkong
europe
...
and assign each concerned article two categories (Category1, Category2):
- parents (countries):
(country, china)etc - children (services):
(china, lcl)…
Then a service-by-country list can be output with
<!-- list of parent articles (countries) -->
<txp:article_custom category="country" match="Category1" wraptag="ul" class="Parent-Articles" break="li">
<txp:permlink><txp:title /></txp:permlink>
<!-- list of child articles if Category2 is the same as parent Category1. -->
<txp:article_custom category='<txp:category2 />' match="Category1" wraptag="ul" class="Child-Articles" break="li">
<txp:permlink><txp:title /></txp:permlink>
</txp:article_custom>
</txp:article_custom>
IIRC, match was introduced in 4.6, so you can test it. The advantage for users is that the category tree is available on Write tab, and one does not need to create ID-named categories. Actually, even <txp:category_list /> could do, I think.
Edit: it’s just a more standard approach, not necessary a cuter one.
Offline