Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-02-10 22:04:30

Bongo-man
Member
Registered: 2009-03-18
Posts: 243

Nested tags to get very compact <txp /> code

I’m trying to make my blog code more compact.

When I search an article in the admin interface of my blog, if I’m looking for all those in the ‘animals’ category, I can see are displayed not only all from the categories ‘animal’, but also: ‘animals-cats’, ‘animals-dogs’, etc.

I’ve tried to get the same in a listing page (whose section is ‘animals-’), calling all the <permalinks /> related to articles from the categories ‘animals-cats’, ‘animals-dogs’, etc. . To get that I used this :

<txp:article_custom category=’<txp:section />’ sort=“Posted desc” wraptag=“p” break=“p” limit=“3”>
<txp:permlink><txp:title /></txp:permlink></txp:article_custom>

but I cannot get anything, why?

I could get some articles if I use this other expression:

<txp:article_custom category=’<txp:section />cats’ sort=“Posted desc” wraptag=“p” break=“p” limit=“3”>
<txp:permlink><txp:title /></txp:permlink></txp:article_custom>

but what I need is to get are listed, in the page placed in the ‘anilmals-’ section, 3 article permalinks coming from all the categories beginning with ‘animals-’; for this reason I tried to use in <txp:article_custom /> the category=’<txp:section />’ above.

Endly I would need also to get all the listed articles from every category have its label, but I realized I cannot get nested, in <txp:article_custom /> , its attribute label=’<category title=“1”/>’ .
Can I achieve it adding a form to <txp:article_custom /> , like a form=“label” containing something like this: <txp:category title=“1” /> ?

Last edited by Bongo-man (2011-02-10 22:08:59)

Offline

#2 2011-02-10 23:59:11

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Nested tags to get very compact <txp /> code

You can first create a parent category for those ‘animal-*’ categories, with the same name as the section, so ‘animal-’. Then you can use something like this:

<txp:category_list parent='<txp:section />' exclude='<txp:section />' wraptag="ul" break="li">
   <txp:category title="1" />
   <txp:article_custom category='<txp:category />' wraptag="ul" break="li" limit="3">
      <txp:permlink><txp:title /></txp:permlink>
   </txp:article_custom>
</txp:category_list>

Offline

#3 2011-02-11 20:16:20

Bongo-man
Member
Registered: 2009-03-18
Posts: 243

Re: Nested tags to get very compact <txp /> code

Thank you very much Els, very good solution, I have also customized adding the articles date and applying the just class to each category title. This template now is more clear and I can better work on it.
Then I’ve tested the page to check the template for its performances and the result was not so good as i waited.

For this reason I’m trying now to use the same script above to get a category list with links to lists of articles; I have tried this solution: http://txptips.com/category-menu-excluding-the-parent , but the list does not display the links (only the category titles). Any solution?

Offline

#4 2011-02-11 21:24:43

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Nested tags to get very compact <txp /> code

Sorry, then I don’t think I understand what you want, because the code example in the TXP Tip is almost the same as my example here. If you want to add the article titles, you only need to add the article_custom tag in there.

But did you really experience serious performance problems? You can check the tag trace, it shows the query times so you can find out which tag(s) is/are causing this. I wouldn’t expect this code to cause significant performance problems.

Offline

#5 2011-02-11 21:49:46

Bongo-man
Member
Registered: 2009-03-18
Posts: 243

Re: Nested tags to get very compact <txp /> code

What I need is to have a list of category title-links addressing to matching lists of articles (by category), almost similar to the one you can see on the right of the Txp-tips page I linked above. I hope it could be possible to get it. I’ve got the list, but without links to matching lists of articles.
I thank you for your help.

The problems depend mainly on the low quality of my hosting service I think.

I’m meeting a not so much serious problems, but my web site is on a shared hosting service with many other web sites and they use to list also some script they don’t like; for this reason I try to prevent to have problems with my server provider.

My worst performance, in the tematic index page with the greatest number of categories listed in, is:

<!— Runtime: 0,2360 —>
<!— Query time: 0,182865 —>
<!— Queries: 34 —>
<!— Memory: 2781Kb, end of textpattern() —>

Removing the article list by category it becames:

<!— Runtime: 0,1216 —>
<!— Query time: 0,091405 —>
<!— Queries: 21 —>
<!— Memory: 2759Kb, end of textpattern() —>

In the RSS feed of the same page, where articles are listed with reference to the (same) article section I have this:

<!— Runtime: 0,0715 —>
<!— Query time: 0,016460 —>
<!— Queries: 11 —>
<!— Memory: 2760Kb, end of textpattern() —>

For this reason I think to list some of them like in the RSS feed, but adding the opportunity to access them choosing a categorized list.

Last edited by Bongo-man (2011-02-11 22:17:24)

Offline

#6 2011-02-12 01:05:12

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Nested tags to get very compact <txp /> code

Bongo-man wrote:

What I need is to have a list of category title-links addressing to matching lists of articles (by category), almost similar to the one you can see on the right of the Txp-tips page I linked above. I hope it could be possible to get it. I’ve got the list, but without links to matching lists of articles.

Ah, I see. You need to change <txp:category title="1" /> to <txp:category title="1" link="1" />.

Offline

#7 2011-02-12 13:41:35

Bongo-man
Member
Registered: 2009-03-18
Posts: 243

Re: Nested tags to get very compact <txp /> code

I did it, but it doesn’t work.

It (almost) works with this expression:

<txp:category_list parent='<txp:section />' exclude='<txp:section />' wraptag="ul" break="" this_section="boolean" children="0">

<li<txp:if_category name='<txp:category />'> class="active"</txp:if_category>>

<txp:category title="1" link="1" />
<txp:article_custom category='<txp:category />' wraptag="ul" limit="3">
<li><txp:permlink><txp:title /></txp:permlink></li>
</txp:article_custom>

</li>

</txp:category_list>

What occurs now is that are listed, for every category, all the articles in the defined limit (Es <txp:article_custom limit=“10” /> ). So I need be listed only the articles from the active category (es. category 1 in the page: in the page http://www.mysite/section/?c=category1 )as follow:

  1. Parent=’<txp:section />’
    1. category1
      1. article1
      2. article2
      3. article3
    2. category2
    3. category3
    4. category4
  2. etc.

OPTION: ‘adi_cat_menu’
I could get it by means of the pluging ‘adi_cat_menu’, setting it to: active_only=“1”, but in this case it links the categories to ‘default’ page (my home page). Could be a solution applying the attribute section=’<txp:section />’, but in this case it lists articles only from the same section and in my case no article is displayed, because all the articles are placed in different sections than that in which they are listed. :-(

—> ENDLY I have found the solution with this simple expression (I’m still customizing) (and also the performance of index page seem to be very improved):

<txp:category_list parent='<txp:section />' exclude='<txp:section />' wraptag="p" break="p" children="0" active_class="activecategory" type="article">

<txp:category link="1" title="1" class="titoloart" section='<txp:section />' wraptag="p" />

<txp:if_category name='<txp:category />'>

<txp:article_custom category='<txp:category />' sort="Posted desc" break="p" limit="35">
<txp:permlink><txp:title /></txp:permlink> - <i>Published on the:</i> <txp:posted wraptag="em" />
</txp:article_custom>

</txp:if_category>

</txp:category_list>

I’m sorry I’m here again, because I can realize I’m in a ‘cul-de-sac’. I’ve explained above about all that I’ve done, but acting this way there are some problems that seem without any solution.
The list of categories I can see now is displayed, as usual, in the index page of each tematic section (a dinamic page, a sort of ‘index article’, i.e. www.mysite.com/section/index.html). When I click one of the category link, I’m addressed to single category pages, listing category-articles.
These pages (i.e. www.mysite.com/section/?c=category1) very similar to the matching index articles appear to be ‘static’ because they don’t display two tematic link menu, the page title and the picture, usually appearing in each index article; these menu are linked to the first category of the article index page (www.mysite.com/section/index.html).

Perhaps they are not really static, the problem for me is that I need to change all the procedure I use to recall the single components of my serie of dinamic index pages. I see I need to call menus and photos reffering to category names matching the index pages section names and for this reason I need to create some categories more.
Endly I hope al this will not slow the server again. :-)

Anyway i don’t stop asking for any different solution:

Are there any alternative solution to get (more easily) a list of article categories linking the matching list of articles so that they can be be listed in the same dinamic page?

I hope for some idea to get a solution. Thanks.

(added bc.. for better code display. -Els)

Last edited by Bongo-man (2011-02-13 18:12:51)

Offline

#8 2011-02-13 12:43:21

Bongo-man
Member
Registered: 2009-03-18
Posts: 243

Re: Nested tags to get very compact <txp /> code

I’m almost arrived to the solution following the way I said in the antecedent message, but I have also realized that could be something wrong in my script:

I’ve noted that if I manually insert the query for one of the category, beyond the complete index page address, as follow:

www.mysite.com/section/index.html?c=category1
instead of:

www.mysite.com/section/?c=category1

all works good: I’ve all my menu, my photo and the page title.

So I ask you, how can I get the category links (of every tematic index page) address to
www.mysite.com/section/index.html?c=category1 instead of www.mysite.com/section/?c=category1
assuming that I have the actual link

specifying -> section='<txp:section />' in the <txp:category /> tag of the script below:

<txp:category_list parent='<txp:section />' exclude='<txp:section />' wraptag="p" break="p" children="0" active_class="activecategory" type="article">

<txp:category link="1" title="1" class="titoloart" section='<txp:section />' wraptag="p" /> 

<txp:if_category name='<txp:category />'>

<txp:article_custom category='<txp:category />' sort="Posted desc" break="p" limit="35">
<txp:permlink><txp:title /></txp:permlink> – <i>Published on the:</i> <txp:posted wraptag="em" />
</txp:article_custom>

</txp:if_category>

</txp:category_list>

If I could practice this solution I would avoid to change many things in my web site.

(edited for better code display. -Els)

Last edited by els (2011-02-13 15:34:08)

Offline

#9 2011-02-13 15:39:57

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Nested tags to get very compact <txp /> code

Bongo-man, just to let you know I’m not ignoring you, I just haven’t had the time to look at your latest posts. I’ll try and look at it later today.

Offline

#10 2011-02-13 16:29:23

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Nested tags to get very compact <txp /> code

Bongo-man wrote:

www.mysite.com/section/index.html?c=category1

What is index.html? Is it an article title? If so, is it a sticky article?

Also it would help if you posted the entire code you have now on your section page.

Last edited by els (2011-02-13 16:30:29)

Offline

#11 2011-02-13 18:02:57

Bongo-man
Member
Registered: 2009-03-18
Posts: 243

Re: Nested tags to get very compact <txp /> code

Els I thank you for paying attention to my script problem, besides I know today is Sunday. I’ve updated many times what I wrote, hoping it become more clear to understand.

…About index.html

It is the name of the index article files, that is index.html .

Applying the textpattern system to my web site I mantained the old structure (installing it in a sub-directory) and many of the old file names.

My index pages are 12, descending from the home and their names are something like:

www.mysite.com/abcd/abcd/namesection/nameyindex.html , but if necessary I can convert them in

www.mysite.com/abcd/abcd/namesection/index.html .

The entire code is very very wide because the page uses again <tables> and <cells> i’m going to switch to complete CSS as soon as possible. The part i think usefull has been reduced very much after recent modification and is only what I pasted above. It is the only part involved in displaying this group of articles (by category) of every of my index pages. Below it I’ve also some code to display some press-releases.

———-
I’ve concluded my work following the most elaborated way, because I needed to use also 2 conditional expression and 12 external forms allowing me to introduce 12 static menus (1 for every section-index page), but endly the page above (now displaying only the link to the category links of articles) has at present the following very improved performance:

<!— Runtime: 0,0606 —>
<!— Query time: 0,025904 —>
<!— Queries: 23 —>
<!— Memory: 2825Kb, end of textpattern() —>

-anyway if I could find a solution for the problem above I could remove also the two conditional expressions.

Last edited by Bongo-man (2011-02-14 01:07:25)

Offline

#12 2011-02-14 19:56:38

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Nested tags to get very compact <txp /> code

I must say that I still don’t get how your site works, with those index.html files… But maybe it’s not important, if this is what you need:

how can I get the category links (of every tematic index page) address to
www.mysite.com/section/index.html?c=category1 instead of www.mysite.com/section/?c=category1

you can try to replace

<txp:category link="1" title="1" class="titoloart" section='<txp:section />' wraptag="p" /> 

with

<p><a class="titoloart" href="<txp:site_url /><txp:section />/index.html?c=<txp:category />"><txp:category title="1" /></a></p>

Let me know if it works.

Offline

Board footer

Powered by FluxBB