Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-01-03 09:34:23

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,521
Website

[Solved] Category landing pages

I am trying to figure out the landing pages for categories in article_lists. Admittedly I did not use categories for many years now and forgot some of the basics. This is what I have which works for the sections landing pages but not for the categories ones. Any help would be greatly appreciated

<txp:if_article_list>
	<txp:if_section name='<txp:section />'>
		<txp:if_search>
			<txp:article pgonly="1" searchall="0" searchsticky="1" />
			<txp:if_search_results>
				<txp:search_result_count />
			<txp:else />
				no results
			</txp:if_search_results>
				<txp:article limit="999" searchall="0" />
		<txp:else />
			<txp:article_custom status="live" section='<txp:section />'' c10="x" form="" limit="999">
				<txp:if_article_category number="1">
					<a rel="follow" href="/<txp:section />/<txp:category1 />/"><txp:title /></a>
				<txp:else />
					<a href="<txp:permlink />" rel="bookmark"><txp:title /></a>
				</txp:if_article_category>
			</txp:article_custom>
			<txp:if_category>
				<txp:evaluate query='<txp:page_url type="pg" /> = 1'>
					<txp:article_custom section='<txp:section />' category='<txp:category />' c10="x">
						<txp:body />
					</txp:article_custom>
				</txp:evaluate>
			</txp:if_category>
		</txp:if_search>
	</txp:if_section>
</txp:if_article_list>

Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | Respbublika! | NeMe @ github

Online

#2 2020-01-03 14:25:30

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,521
Website

Re: [Solved] Category landing pages

Solved!! Here is the code. I have another question which I will post in another thread.

<txp:if_article_list>
	<txp:if_section name='<txp:section />'>
		<txp:if_search>
			<txp:article pgonly="1" searchall="0" searchsticky="1" />
			<txp:if_search_results>
				<txp:search_result_count />
			<txp:else />
				no results
			</txp:if_search_results>
				<txp:article limit="999" searchall="0" />
		<txp:else />
			<txp:if_category>
				<txp:evaluate query='<txp:page_url type="pg" /> = 1'>
					<txp:article_custom section='<txp:section />' category='<txp:category />' break="article" c10="" />
				</txp:evaluate>
			<txp:article_custom status section='<txp:section />'' c10="x" form="" limit="999">
				<txp:if_article_category number="1">
					<a rel="follow" href="/<txp:section />/<txp:category1 />/"><txp:title /></a>
				<txp:else />
					<a href="<txp:permlink />" rel="bookmark"><txp:title /></a>
				</txp:if_article_category>
			</txp:article_custom>
			</txp:if_category>
		</txp:if_search>
	</txp:if_section>
</txp:if_article_list>

Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | Respbublika! | NeMe @ github

Online

#3 2020-01-03 20:02:03

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,657
Website

Re: [Solved] Category landing pages

Glad you got it working. You have a fairly special situation there that I’m not sure I’ve fully understood (i.e what c10 is for).

The very basics – for anyone else less familiar with txp who chances on this thread – is that txp:article (without _custom) generally takes care of responding to categories (and sections, and search, and list view vs. individual article view) passed to the page through the url on its own.

In txp 4.8.0 I believe the regular txp:article has gained new powers and can respond to custom field contexts coming through the url as well, though I have yet to explore it fully. But it made me wonder whether you might be able to simplify a lot of your code by use txp:article in conjunction with c10="x" or c10="" as additional attributes. The docs say you can use customfieldname as a filtering attribute and your other attributes, e.g. section='<txp:section />' category='<txp:category />' are just passing in the current page’s context manually, which txp:article already picks up on (status too).


TXP Builders – finely-crafted code, design and txp

Offline

#4 2020-01-03 20:25:40

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,521
Website

Re: [Solved] Category landing pages

Intriguing!! What you are suggesting is that I can achieve the above with just

<txp:if_article_list>
	<txp:if_section name='<txp:section />'>
		<txp:if_search>
			<txp:article pgonly="1" searchall="0" searchsticky="0" />
			<txp:if_search_results>
				<txp:search_result_count />
			<txp:else />
				no results
			</txp:if_search_results>
				<txp:article limit="999" searchall="0" />
		<txp:else />
			<txp:if_category>
				<txp:article break="article" c10="" />
			<txp:article c10="x" form="" limit="999">
				<txp:if_article_category number="1">
					<a rel="follow" href="/<txp:section />/<txp:category1 />/"><txp:title /></a>
				<txp:else />
					<a href="<txp:permlink />" rel="bookmark"><txp:title /></a>
				</txp:if_article_category>
			</txp:article_custom>
			</txp:if_category>
		</txp:if_search>
	</txp:if_section>
</txp:if_article_list>

Or it could even be shorter than that?


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | Respbublika! | NeMe @ github

Online

#5 2020-01-03 21:26:03

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,657
Website

Re: [Solved] Category landing pages

I’m guessing at how you’re using your c10 custom field (e.g. only in category cases and the empty case should only show on the first page) but maybe something like this:

<txp:if_search>

    <txp:article pgonly="1" searchall="0" />
	<txp:if_search_results>
		<txp:search_result_count />
		<txp:article limit="999" searchall="0" />
	<txp:else />
		no results
	</txp:if_search_results>

<txp:else />

    <txp:if_category>

        <txp:evaluate query='<txp:page_url type="pg" /> = 1'>
    	    <!-- shown on first page only -->
    	    <txp:article break="article" c10="" />
    	</txp:evaluate>

        <txp:article c10="x" limit="999">
    		<txp:if_article_category number="1">
    			<a rel="follow" href="/<txp:section />/<txp:category1 />/"><txp:title /></a>
    		<txp:else />
    			<a href="<txp:permlink />" rel="bookmark"><txp:title /></a>
    		</txp:if_article_category>
    	</txp:article>

    <txp:else />

        <!-- your regular txp:article tag for all other cases -->
        <txp:article listform="your_listform" form="individual_article_form" limit="999" />

    </txp:if_category>

</txp:if_search>

The search case is always a list page as is the category case, so you shouldn’t need to check for article_list context (unless you have other stuff going on). Similarly, checking that the current section is the current section shouldn’t be necessary.

Another idea: txp:article can also take a searchform attribute so you might be able to omit the outer if_search case by including that attribute in the “all other cases” txp:article tag and wrapping it in txp:evaluate to catch the “no results” case to display the message. Perhaps something like:

<txp:if_category>

    <txp:evaluate query='<txp:page_url type="pg" /> = 1'>
	    <!-- on first page only -->
	    <txp:article break="article" c10="" />
	</txp:evaluate>

    <txp:article c10="x" limit="999">
		<txp:if_article_category number="1">
			<a rel="follow" href="/<txp:section />/<txp:category1 />/"><txp:title /></a>
		<txp:else />
			<a href="<txp:permlink />" rel="bookmark"><txp:title /></a>
		</txp:if_article_category>
	</txp:article>

<txp:else />

    <!-- your regular txp:article tag for all other cases -->
    <txp:evaluate test="article">
        <txp:article listform="your_listform" form="individual_article_form" searchform="search_results_form" limit="999" />
    <txp:else />
        <!-- no articles found -->
        <txp:variable name="matches" value="none" />
    </txp:evaluate>

    <txp:if_search>
        <txp:if_variable name="matches" value="none">
            no results
        </txp:if_variable>
    </txp:if_search>

</txp:if_category>

It’s marginally shorter but arguably not so readable.

I’ve not tested either variant (especially whether no search matches can also be detected using txp:evaluate) but maybe it provides some ideas.


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB