Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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 | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Online
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)
Offline
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 | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Online
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)
Offline
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 | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Online
Offline
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 | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Online
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
Offline
Re: [SOLVED] get the value of a custom field in a variable
I’ll investigate it further. It’s strange that the validator does not show an error.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Online
Re: [SOLVED] get the value of a custom field in a variable
jakob wrote #302412:
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”:
Per spec (and the extension in the microformat text), rel="canonical"
is indeed allowed the <a>
and <area>
elements. Text here (WHATWG text) — read the last paragraph there, quoted below, and here (Microformats).
Types defined as extensions in the microformats wiki existing-rel-values page with the status “proposed” or “ratified” may be used with the rel attribute on link, a, and area elements in accordance to the “Effect on…” field.
I’m not convinced it is a good idea to do that, though.
Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
Offline
Re: [SOLVED] get the value of a custom field in a variable
phiw13 wrote #302415:
Per spec (and the extension in the microformat text),
rel="canonical"
is indeed allowed the<a>
and<area>
elements. Text here (WHATWG text) — read the last paragraph there, quoted below, and here (Microformats).
Oh well, if I got it wrong, I apologise. I can see that that quote applies to rel
tags in general, and then refers to the table. But is that entry in the table right? It conflicts with pretty much all other information on canonical urls.
EDIT: It looks like the table was updated by Jeremy Keith (adactio) (diff) from not allowed to hyperlink, and he is someone who knows what he is doing.
—
So, if you do use it on an a
link, presumably it is overridden if the destination page has its own canonical url defined?
TXP Builders – finely-crafted code, design and txp
Offline
Re: [SOLVED] get the value of a custom field in a variable
Well… l deleted the rel=canonical anyway as most of the info I found also made me to jumb in the same conclusion as Julian.
An off topic question. Can we have <a rel="author external" href="...
. According to many pages I read, we can, but what happens if the author has no online presence? Can we have <span rel="author">...
?
> Edited to add. Or could the second one be <span itemprop="author">..
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Online