Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2017-08-28 16:50:29

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,032
Website GitHub Mastodon Twitter

Re: txp:article_custom via php echo

zenman wrote #306742:

Hello!

Is there any way to make txp:article_custom work with url ? Something like this:

<txp:article_custom url="page.html" />...

I assume it can be done using the url field somehow through php?

Hi zenman and welcome to txp.

The short answer to your question is No.

You can however, if the url you wish to show is part of the txp database, use: <txp:article_custom id="45" /> – You have to of course replace the id number to the id you wish to parse. You can read more about the article custom tag in the documentation.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#14 2017-08-28 16:58:54

zenman
Member
Registered: 2017-08-28
Posts: 41
Website

Re: txp:article_custom via php echo

colak wrote #306743:

Hi zenman and welcome to txp.

The short answer to your question is No.

You can however, if the url you wish to show is part of the txp database, use: <txp:article_custom id="45" /> – You have to of course replace the id number to the id you wish to parse. You can read more about the article custom tag in the documentation.

Thanx. Oh, how sad. Yes, I know about Article_ID. Is there any other way I can get an article by its url?

Last edited by zenman (2017-08-28 17:01:35)

Offline

#15 2017-08-28 19:49:16

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,305

Re: txp:article_custom via php echo

zenman wrote #306744:

Is there any other way I can get an article by its url?

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.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#16 2017-08-29 06:50:40

zenman
Member
Registered: 2017-08-28
Posts: 41
Website

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

#17 2017-08-29 08:24:14

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,616
Website

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

#18 2017-08-29 20:02:13

zenman
Member
Registered: 2017-08-28
Posts: 41
Website

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 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 -->...

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: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.

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,305

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
Website

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”
  • 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

#21 2017-08-30 05:38:48

zenman
Member
Registered: 2017-08-28
Posts: 41
Website

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

#22 2017-08-30 06:00:45

zenman
Member
Registered: 2017-08-28
Posts: 41
Website

Re: txp:article_custom via php echo

makss wrote #306779:

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...

  • 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=" &#187; " title="1" wraptag="" />
<txp:if_article_category>
<txp:article_custom id='<txp:category1  />'>
<txp:if_article_category>
<txp:article_custom id='<txp:category1  />'>
 &#187;  <txp:permlink><span><txp:custom_field name="info_1" /></span></txp:permlink>
</txp:article_custom> 
</txp:if_article_category>
&#187;  <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

#23 2017-08-30 17:07:01

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,032
Website GitHub Mastodon Twitter

Re: txp:article_custom via php echo

Hi zenman,

I see a couple of problems with your code

  1. breadcrumb tag is not closed
  2. <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

#24 2017-08-30 18:00:24

zenman
Member
Registered: 2017-08-28
Posts: 41
Website

Re: txp:article_custom via php echo

colak wrote #306784:

Hi zenman,

I see a couple of problems with your code

  1. breadcrumb tag is not closed
  2. <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

Board footer

Powered by FluxBB