Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2016-10-22 17:30:20

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

Re: [SOLVED] get the value of a custom field in a variable

I’m still working on this:)

<div class="sub">
<txp:etc_query name="find" data='<txp:custom_field name="venue" />' markup="list" break=" OR " >FIND_IN_SET({?}, custom_3)</txp:etc_query>
<txp:variable name="moretexts"><txp:article_custom limit="20" section="texts" break="," sort="rand()" exclude='<txp:article_id />'><txp:article_id /></txp:article_custom></txp:variable>
<txp:if_variable name="find" value="">
<txp:article_custom section="texts" sort="rand()" limit="20" break="li" wraptag="ul" class="submenu" label="Other Texts" labeltag="h4" id='<txp:variable name="moretexts" />' exclude='<txp:article_id />'> 
<a rel="canonical" href="<txp:permlink />"><txp:title /></a>
</txp:article_custom>
<txp:else />
<txp:etc_query name="relatedtexts" data='(<txp:variable name="find" />) AND ID != <txp:article_id />' markup="db" populate="article" break=","><txp:article_id /></txp:etc_query>
<txp:article_custom id='<txp:variable name="relatedtexts" />' limit="20" break="li" wraptag="ul" class="related_articles" label="More texts by the author" labeltag="h4">
<a rel="canonical" href="<txp:permlink />"><txp:title /></a>
</txp:article_custom>
<txp:article_custom sort="rand()" section="texts" exclude='<txp:article_id />,<txp:variable name="find" />' limit="15" break="li" wraptag="ul" class="submenu" label="Other Texts" labeltag="h4"> 
<a rel="canonical" href="<txp:permlink />"><txp:title /></a>
</txp:article_custom>
</txp:if_variable>
</div>

the above mostly works as expected and differently to my initial question in this thread.

The problem: When an author has more texts all appears as expected but when we only have one text, a random list from all sections is populated.. Is there something wrong with my conditionals in there?


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

Offline

#12 2016-10-22 17:47:36

etc
Developer
Registered: 2010-11-11
Posts: 3,127
Website

Re: [SOLVED] get the value of a custom field in a variable

The condition <txp:if_variable name="find" value=""> is never met. This variable

  • either contains a db query like FIND_IN_SET(2, custom_3) OR FIND_IN_SET(5, custom_3) if current venue is 2,5;
  • or is not set if this field is empty (i.e. the current article has no declared authors).

You should somehow check <txp:if_variable name="relatedtexts"> instead.

…to be continued…


etc_[ query | search | pagination | date | tree | cache ]

Offline

#13 2016-10-22 17:54:32

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

Re: [SOLVED] get the value of a custom field in a variable

Thanks so much Oleg. That did it. Final code for those who would like to use it.

<div class="sub">
<txp:etc_query name="find" data='<txp:custom_field name="venue" />' markup="list" break=" OR " >FIND_IN_SET({?}, custom_3)</txp:etc_query>
<txp:variable name="moretexts"><txp:article_custom limit="20" section="texts" break="," sort="rand()" exclude='<txp:article_id />'><txp:article_id /></txp:article_custom></txp:variable>
<txp:etc_query name="relatedtexts" data='(<txp:variable name="find" />) AND ID != <txp:article_id />' markup="db" populate="article" break=","><txp:article_id /></txp:etc_query>
<txp:if_variable name="relatedtexts" value="">
<txp:article_custom section="texts" sort="rand()" limit="20" break="li" wraptag="ul" class="submenu" label="Other Texts" labeltag="h4" id='<txp:variable name="moretexts" />' exclude='<txp:article_id />'> 
<a rel="canonical" href="<txp:permlink />"><txp:title /></a>
</txp:article_custom>
<txp:else />
<txp:article_custom id='<txp:variable name="relatedtexts" />' limit="20" break="li" wraptag="ul" class="related_articles" label="More texts by the author" labeltag="h4">
<a rel="canonical" href="<txp:permlink />"><txp:title /></a>
</txp:article_custom>
<txp:article_custom sort="rand()" section="texts" exclude='<txp:article_id />,<txp:variable name="find" />' limit="15" break="li" wraptag="ul" class="submenu" label="Other Texts" labeltag="h4"> 
<a rel="canonical" href="<txp:permlink />"><txp:title /></a>
</txp:article_custom>
</txp:if_variable>
</div>

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

Offline

#14 2016-10-22 19:18:21

etc
Developer
Registered: 2010-11-11
Posts: 3,127
Website

Re: [SOLVED] get the value of a custom field in a variable

colak wrote #302395:

That did it.

Not yet, there are few glitches. I would suggest

<txp:etc_query name="find" data='<txp:custom_field name="venue" />' markup="list" break=" OR " >FIND_IN_SET({?}, custom_3)</txp:etc_query>
<txp:if_variable name="find">
	<txp:etc_query name="relatedtexts" data='(<txp:variable name="find" />) AND ID != <txp:article_id />' markup="db" populate="article" break=","><txp:article_id /></txp:etc_query>
</txp:if_variable>
<txp:if_variable name="relatedtexts">
	<txp:article_custom id='<txp:variable name="relatedtexts" />' limit="20" break="li" wraptag="ul" class="related_articles" label="More texts by the author" labeltag="h4">
		<a rel="canonical" href="<txp:permlink />"><txp:title /></a>
	</txp:article_custom>
</txp:if_variable>
<txp:article_custom sort="rand()" section="texts" exclude='<txp:article_id />,<txp:variable name="relatedtexts" />' limit='<txp:if_variable name="relatedtexts">15<txp:else />20</txp:if_variable>' break="li" wraptag="ul" class="submenu" label="Other Texts" labeltag="h4">
	<a rel="canonical" href="<txp:permlink />"><txp:title /></a>
</txp:article_custom>

Last edited by etc (2016-10-23 07:49:10)


etc_[ query | search | pagination | date | tree | cache ]

Offline

#15 2016-10-23 04:34:01

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

Re: [SOLVED] get the value of a custom field in a variable

etc wrote #302400:

Not yet, there are few glitches. I would suggest

<txp:etc_query name="find" data='<txp:custom_field name="files" />' markup="list" break=" OR " >FIND_IN_SET({?}, custom_1)</txp:etc_query>...

Oleg, are you sure? I actually did pick up my <txp:variable name="relatedtexts" /> mistake but regarding the first line, I have no custom field named files.


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

Offline

#16 2016-10-23 07:09:23

etc
Developer
Registered: 2010-11-11
Posts: 3,127
Website

Re: [SOLVED] get the value of a custom field in a variable

Oops, sorry, Yiannis, corrected. I have a files field :)

Edit: you can even spare one db query:

<txp:etc_query name="find" data='<txp:custom_field name="venue" />' markup="list" break=" OR " >FIND_IN_SET({?}, custom_3)</txp:etc_query>
<txp:if_variable name="find">
	<txp:etc_query data='(<txp:variable name="find" />) AND ID != <txp:article_id />' markup="db" populate="article"  wraptag="ul" class="related_articles" label="More texts by the author" labeltag="h4">
		<txp:variable name="relatedtexts" value='<txp:variable name="relatedtexts" />,<txp:article_id />' />
		{$<({#row}|21).?(<li><a rel="canonical" href="<txp:permlink />"><txp:title /></a></li>)}
	</txp:etc_query>
</txp:if_variable>
<txp:article_custom sort="rand()" section="texts" exclude='<txp:article_id /><txp:variable name="relatedtexts" />' limit='<txp:if_variable name="relatedtexts">15<txp:else />20</txp:if_variable>' break="li" wraptag="ul" class="submenu" label="Other Texts" labeltag="h4">
	<a rel="canonical" href="<txp:permlink />"><txp:title /></a>
</txp:article_custom>

Last edited by etc (2016-10-23 09:48:56)


etc_[ query | search | pagination | date | tree | cache ]

Offline

#17 2016-10-23 07:47:44

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

Re: [SOLVED] get the value of a custom field in a variable

Nope that does not work. When related articles exist, it parses the list and heading correctly but the Other texts heading is also appearing without a list of texts. When there are no related texts, it creates a list with random articles from the whole of the site using the More texts by the author heading, and shows the Other texts heading without a list below it.

This does work as expected (similar to my previous post but with the minor correction.)

<txp:etc_query name="find" data='<txp:custom_field name="venue" />' markup="list" break=" OR " >FIND_IN_SET({?}, custom_3)</txp:etc_query>
<txp:variable name="moretexts"><txp:article_custom limit="20" section="texts" break="," sort="rand()" exclude='<txp:article_id />'><txp:article_id /></txp:article_custom></txp:variable>
<txp:etc_query name="relatedtexts" data='(<txp:variable name="find" />) AND ID != <txp:article_id />' markup="db" populate="article" break=","><txp:article_id /></txp:etc_query>
<txp:if_variable name="relatedtexts" value="">
<txp:article_custom section="texts" sort="rand()" limit="20" break="li" wraptag="ul" class="submenu" label="Other Texts" labeltag="h4" id='<txp:variable name="moretexts" />' exclude='<txp:article_id />'> 
<a rel="canonical" href="<txp:permlink />"><txp:title /></a>
</txp:article_custom>
<txp:else />
<txp:article_custom id='<txp:variable name="relatedtexts" />' limit="20" break="li" wraptag="ul" class="related_articles" label="More texts by the author" labeltag="h4">
<a rel="canonical" href="<txp:permlink />"><txp:title /></a>
</txp:article_custom>
<txp:article_custom sort="rand()" section="texts" exclude='<txp:article_id />,<txp:variable name="relatedtexts" />' limit="15" break="li" wraptag="ul" class="submenu" label="Other Texts" labeltag="h4"> 
<a rel="canonical" href="<txp:permlink />"><txp:title /></a>
</txp:article_custom>
</txp:if_variable>

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

Offline

#18 2016-10-23 07:50:43

etc
Developer
Registered: 2010-11-11
Posts: 3,127
Website

Re: [SOLVED] get the value of a custom field in a variable

colak wrote #302405:

Nope that does not work.

I had section="tips" instead of section="texts", corrected too now.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#19 2016-10-23 09:30:40

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

Re: [SOLVED] get the value of a custom field in a variable

Thanks so much Oleg. That actually works!!! I’m still trying to understand it though….


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

Offline

#20 2016-10-23 10:26:04

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

Re: [SOLVED] get the value of a custom field in a variable

colak wrote #302410:

Thanks so much Oleg. That actually works!!! I’m still trying to understand it though….

I was impressed by your earlier “now possible in v4.6” simplification but your new version is mind-boggling. I’d love to see the explanation of that too.

BTW: Yiannis, I don’t think you can (or should) use rel="canonical" on anchor links. It belongs in the page head in the format as an instruction that says “this is this page’s url, regardless of how you got here”:

<link rel="canonical" href="http://mydomain.com/this-pages-definitive-url" />

If it were possible to set it on an a link, it would make multiple canonical definitions possible which defeats its purpose.


TXP Builders – finely-crafted code, design and txp

Online

Board footer

Powered by FluxBB