Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2024-11-06 05:45:56

code365
Member
From: California
Registered: 2009-08-16
Posts: 117

Match article with categories

Hi TXP Community,

Hopefully, this makes sense. I have a section called coaching. I have a coaching dropdown menu (URL link) which pulls several article titles from the categories name coach.

I am trying to have it when someone clicking on anyone article title, it brings up the main article along with the additional articles associated to the article. I can get a single article to display on the page, but not the associate articles to show on the page.

Would it be possible to do this with TXP? And if so, can you please help?

Thank you,

Offline

#2 2024-11-06 06:33:03

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

Re: Match article with categories

related_articles returns articles from the same section and category. You can achieve similar results with article_custom.


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

Offline

#3 2024-11-06 07:11:48

code365
Member
From: California
Registered: 2009-08-16
Posts: 117

Re: Match article with categories

Colak,

I am able to return the articles from the category, but the added article is not attached to the article. It displays the same article for the main article. Should I create a sub category folder under the main category with the article?

Last edited by code365 (2024-11-06 07:19:48)

Offline

#4 2024-11-06 07:22:53

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,538
Website GitHub Twitter

Re: Match article with categories

Hi

How you decide wich article is related to another ? same category ? same section ? or what ?

Cheers.

Offline

#5 2024-11-06 09:52:27

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

Re: Match article with categories

Colak’s tip is good. Check the related_articles examples for how to use the tag.

You’d use this on the individual_article view, either in your page template by adding your related_articles tag to the <txp:if_individual_article>…</txp:if_individual_article> section of the page template, or alternatively – depending on your page layout – in the form you use to display a main article.

When you click on your article title, it should then show a page with the main article (displayed using the regular txp:article tag) and then related articles in the same category or categories using the txp:related_articles tag.


TXP Builders – finely-crafted code, design and txp

Offline

#6 2024-11-06 13:53:10

code365
Member
From: California
Registered: 2009-08-16
Posts: 117

Re: Match article with categories

@Dragondz, that is what I am trying to understand. The example TXP provides is only a brief description.

@jakob is it possible to point me or give example better example than TXP short example. I am still trying to get my head wrapped around on how to use TXP tags injunction with other TXP tags in complex projects, like this one.

This is one of the reasons I love using TXP because of it community support.

Thank you, TXP community

Last edited by code365 (2024-11-06 18:28:18)

Offline

#7 2024-11-06 21:50:20

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

Re: Match article with categories

code365 wrote #338147:

@jakob is it possible to point me or give example better example than TXP short example. I am still trying to get my head wrapped around on how to use TXP tags injunction with other TXP tags in complex projects, like this one.

The examples in the docs are already informative. It probably becomes clearer if you try it out. Here’s a very simple setup with the related_articles tag in the context of a setup similar to what you described above:

<!-- navigation / select menu -->
<nav>
    <select name="select_menu" onchange="document.location.href=this.value">
        <option selected value="">Select an article</option>
    <txp:article_custom section="coaching" break="" wraptag="">
        <option value="<txp:permlink />"<txp:if_article_id> selected</txp:if_article_id>><txp:title /></option>
    </txp:article_custom>
    </select>
</nav>

<!-- main content -->
<main>
    <!-- article list on section landing page / individual article on article url -->
    <txp:article />
</main>

<!-- sidebar -->
<aside>
    <!-- if showing an individual article ... -->
    <txp:if_individual_article>
        <!-- ... show related articles by category, excluding the current article -->
        <txp:related_articles wraptag="ul" break="li" class="related-article-list" label="Related articles" labeltag="h3" />
    </txp:if_individual_article>
</aside>

This gives you:

  • a select menu at the top built with article_custom. txp:article_custom ignores the current context, so you need to specify the section for the articles to show. This is just an example and might be part of your main nav.
  • on your coaching landing page: an article list in the main content area
    on an individual coaching article: the article content
    This is context-sensitive: it will use whatever form you specify in the listform attribute for the domain.com/section/ url (by default the article_listing form) and whatever form you specify in the form attribute for displaying an individual article (by default the default form). Create your own forms and specify the attributes to customise your output.
  • on an individual article, a list of other articles with a matching category. This is context-sensitive in that it looks at the categories assigned for the current article and lists other articles that are assigned to the same categories, excluding the current article that is showing. Here too, you can provide a form attribute to customise the output. The standard output is <txp:permlink><txp:title /></txp:permlink />.

TXP Builders – finely-crafted code, design and txp

Offline

#8 2024-11-07 08:49:03

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,538
Website GitHub Twitter

Re: Match article with categories

code365 wrote #338147:

@Dragondz, that is what I am trying to understand. The example TXP provides is only a brief description.

Thank you, TXP community

Hi

The related article tag wil give you other articles having the same category or section you can check the doc :

txp:relaterd_articles

Using the match option you can choose what kind of relationship between articles you want.

Cheers.

Offline

#9 2024-11-07 16:37:10

code365
Member
From: California
Registered: 2009-08-16
Posts: 117

Re: Match article with categories

Dragondz Jakob thank you for introducing me to this tag.

Here is a link: http://devstage.jasonstringer.me/coaching/school-community-engagement to the project I am working on.

If you look at “other services” you will see links. When you click on a link, the main content changes, but the related articles are not changing with the associated article.

Should I create a separate category for each link and include the main article and related articles?

Offline

#10 2024-11-07 16:49:42

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

Re: Match article with categories

I guess you are talking about:

Article 2 – Belong to School & Community Engagement
Article 3 – Belong to Coaching services
Article 1 – Belong to Professional Development

Should they change? It appears that they are all under the coaching section. Not sure if they are also under a category.


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

Offline

#11 2024-11-07 17:26:47

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

Re: Match article with categories

Should I create a separate category for each link and include the main article and related articles?

Assuming your articles under “Other services” and the dropdown menu are in the “coaching” section but you want only the relevant article(s) to show with each service, then yes, I would make categories for “school and community engagement”, “coaching services” and “professional development” and then assign those categories to both the main article and the associated articles.


TXP Builders – finely-crafted code, design and txp

Offline

#12 2024-11-07 17:28:19

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,445
Website GitHub

Re: Match article with categories

What is the code you’re using to build the page and the sidebar now? That will help us guide you towards a solution.

And do you want that “other services” box to exclude the link to the current article too?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Online

Board footer

Powered by FluxBB