Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2014-10-28 20:53:59

ingleslenobel
Member
Registered: 2014-10-16
Posts: 88

[SOLVED] if exist 'blocs'

Hello,

I am using textpattern to make a blog section on my site and I have managed to get it working that it actually uses a different script’s forms and stored comments etc, it works ok. I would like to do some other things:

*Rather than a whole site sidebar with fixed links, I’d like to add individual different links to individual articles. I gather I can make a form that’d show these for me but what would experienced hands recommend as the way to store the URLs & text, custom variables per page or is there something that might be better suited?
*Same, I’d like to add a bloc of ‘related articles’ at the bottom of blog entries, graphical square icons which are /directory/em-100.jpg of the link chosen, up to 5. ie like this. Usually a script but I’d prefer to do them individually per page. Can I use a similar thing to the above – what would people suggest?

Thank you very much,
-Johan

Offline

#2 2014-10-28 23:19:38

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

Re: [SOLVED] if exist 'blocs'

Hi Johan,

It depends really on how you want to relate other articles to your current article and how you organise your site.

Textpattern has the txp:related_articles tag which will list however many articles you ask it for that relate to the current article based on sharing a common category or category combination. You can set it to use a specific form and to output the related articles as thumbnails.

<txp:related articles limit="5" wraptag="ul" break="li" form="related_article_thumbs" />

If you want other articles in the same section as the current article, you can use the article_custom with the section attribute. You can feed the current articles section using the tag-in-tag method and single quotes, e.g.

<txp:article_custom section='<txp:section />' limit="5" form="related_articles" wraptag="ul" break="li" />

If you want to specify specific articles that relate to your article, you could use something like a custom field to hold that information. I often store these in the form of Article ID numbers, either a single number or a list of article id numbers separated by commas. You can feed this value back into txp:article_custom using the id attribute, again using the tag-in-tag method with single quotes, e.g.

<txp:article_custom id='<txp:custom_field name="associated_articles" />' limit="5" form="related_articles" wraptag="ul" break="li" />

BTW: you might find wet_quicklink helps here.

Txptips has a few tutorials too if you search there for related, including this one and this one.

Two more options:

  • If you’d like to show current favourites or topical articles that change from time to time a plugin like bloke’s smd_featured is the way to go.
  • If you’d like to always show a specific selection of hand-picked articles when on a particular category page (or a page in that category), you could use adi_variable to store your choice of articles to show for a particular category (for example a comma-separated list of ID numbers as above). Then use a combination of txp:if_category (or txp:if_article_category when viewing an individual article) and the article_custom example above, but use the variable name instead of custom_field.

TXP Builders – finely-crafted code, design and txp

Offline

#3 2014-10-28 23:59:35

ingleslenobel
Member
Registered: 2014-10-16
Posts: 88

Re: [SOLVED] if exist 'blocs'

Thank you very much gents!!

Unfortunately this isn’t quite what I’m lookg for – I should have explained that the right hand panel ‘related links’ would be a collection of links to outside websites/urls, pages related to the particular topic that the article is about. Ie unique for every article. One way I thought this might work would be to create a form/template, call it in on ‘complementary’ and then throw in custom variables attached to each page, which would hold the url and anchor text. But on an for each/if exists type basis, ie if I have 8 urls I’d like to link then it shouldn’t show a template 10 links. Sorry but this is where my limitation in programming is probably very evident.

With the related links at the bottom of the articles, again this is unique per page and mainly links to the non blog section of the site, which at most would be 5 because that’s all the room I have – and consistent with the rest of the site. So some widget where I’d specify the url and the anchor text, which would then call the graphic for that page (all named em-100.jpg under the page directory) and build a dinky bloc… same question though, if exists/for each.

Offline

#4 2014-10-29 04:31:46

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

Re: [SOLVED] if exist 'blocs'

One way to achieve it is by creating link categories and adding those external sites in the links tab.

You can then call them via custom field. If for example you create a custom filed and name it linksfield. You can then add the name of the links category for that article in there and call it with something like

<txp:linklist category='<txp:custom_field name="linksfield" />' limit="10" wraptag="ul" break="li" />
<a rel="external" href="<txp:link_url />"><txp:link_name escape="html" /></a>
</txp:linklist>

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

Offline

#5 2014-10-29 08:52:36

ingleslenobel
Member
Registered: 2014-10-16
Posts: 88

Re: [SOLVED] if exist 'blocs'

Looks like this will work – <txp:if_custom_field name=“whatever”> Do something </txp:if_custom_field>

Offline

#6 2014-10-29 09:56:19

ingleslenobel
Member
Registered: 2014-10-16
Posts: 88

Re: [SOLVED] if exist 'blocs'

I’m sooooo close! But I’ve run into a limitation – 10 custom fields. Is there any way to use a single custom field to store | separated values like url1 | linktext1 | url2 | linktext2 | url3 | linktext3 etc and then to get out a list of urls from this in a “li” ie “li” “li – a href=“url1” “linktext” “end a” “end li”.

Sorry to be so needy – tried searching but couldn’t find something to fit the bill. glz_custom_fields looks a possibility but no idea if it works on latest version of textpattern..?

Offline

#7 2014-10-29 09:58:06

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

Re: [SOLVED] if exist 'blocs'

EDIT: hadn’t seen your post while I was writing, but this should help you. Yes the version of glz_custom_fields on github works with the current version, and my second example at the bottom shows a similar idea to yours…

Ah, I obviously misinterpreted you totally. Sorry…

Yiannis’ approach is a good one, especially if you want to show the same set of links and maybe add to them or change them later. You’re limited to the fields you can use in the links panel, though.

If, however, you find yourself making a new link category and set of links for more or less every single article, it may be simpler to add them to each article individually in a custom field. As you’re adding a bit more material, you can use glz_custom_fields to make additional custom fields in the form of textareas. Then you can use txp:if_custom_field like you say to only show the links if they actually exist, and then you have a number of options:

1. Enter your links in textile syntax in your custom field and then use pm_textile or smd_wrap to process the custom_field as textile. (the body and excerpt fields are the only ones that are pre-parsed as textile). For example, a custom field called related_article_links that looks something like this:

* "This":http://www.mysite.com/article-url-this
* "That":http://www.mysite.com/article-url-that
* "The Other":http://www.mysite.com/article-url-the-other

or however you want to show it, and then:

<txp:if_custom_field name="related_article_links" value=""><txp:else />
  <txp:smd_wrap transform="textile">
    <txp:custom_field name="related_article_links" />
  </txp:smd_wrap>
</txp:if_custom_field>

2. Store just the links, and perhaps your blurb in the custom field like so with a separator in the middle that doesn’t occur in either the link blurb or the link (or in smd_wrap, see below) and a comma at the end:

My intro blurb on this article -- http://www.mysite-com/article-url-this,
My intro blurb on that article -- http://www.mysite-com/article-url-this,
My intro blurb on the other article -- http://www.mysite-com/article-url-the-other

And then use rah_repeat and smd_wrap to construct your own html output from this information, for example

<txp:rah_repeat value='<txp:custom_field name="related_article_links" />' break="li" wraptag="ul"> 

  <txp:variable name="this_link_desc"><txp:smd_wrap transform="split|--||first"><txp:rah_repeat_value /></txp:smd_wrap></txp:variable>
  <txp:variable name="this_link_url"><txp:smd_wrap transform="split|--||last"><txp:rah_repeat_value /></txp:smd_wrap></txp:variable>

  <a href="<txp:variable name="this_link_url" />" title="<txp:variable name="this_link_desc" />">
    <img src="<txp:variable name="this_link_url" />/em-100.jpg" alt="<txp:variable name="this_link_desc" />">
    <h3><txp:variable name="this_link_desc" /></h3>
  </a>

</txp:rah_repeat>

(untested: if it doesn’t like the double dash as separator, try something else like an @)

You don’t have to use the variables, especially if the code you want to output is simpler. You could also nest rah_repeat inside of rah_repeat and use txp:rah_repeat_if_first and txp:rah_repeat_if_last to create the variables. See the example on the rah_repeat plugin page.


TXP Builders – finely-crafted code, design and txp

Offline

#8 2014-10-29 10:08:14

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

Re: [SOLVED] if exist 'blocs'

colak wrote #285183:

One way to achieve it is by creating link categories and adding those external sites in the links tab.

Yes, my post (before I deleted it because I realised it didn’t answer the question) did something along these lines. I suggested setting up similar category trees for both articles and links, then using that as the match in the linklist tag (category='<txp:category1 />', for example, after testing if category1 was set). You could also extend this to match either category by employing txp:variable to stash the categories that were set.

That would render a set of links that were the same for all articles in particular categories (which I thought seemed reasonable given their nature for grouping similar content) but it seems ingleslenobel wants a different link list per article, hence why I deleted my post and bowed to the custom field suggestions, which are more flexible.


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

Offline

#9 2014-10-29 10:23:01

ingleslenobel
Member
Registered: 2014-10-16
Posts: 88

Re: [SOLVED] if exist 'blocs'

Gents, sorry if I wasn’t clear =(

This looks great, and thanks for the confirmation with glz_custom_fields . I’ll get working on it!!!

Offline

#10 2014-10-29 13:45:34

ingleslenobel
Member
Registered: 2014-10-16
Posts: 88

Re: [SOLVED] if exist 'blocs'

Working now thanks – example

snippet:

<txp:if_custom_field name="linksbody1url">
 <a name="widget"></a><div id="relatedlinks">
 <h3>Related Articles</h3>
 <table align="left" border=0 cellspacing=0 cellpadding=0 width="100%" id="relatedtable"><tr align="left" valign="middle"><td width="1%"></td>
 <td width="17%"><p><a href="<txp:custom_field name="linksbody1url" />"><img alt="<txp:custom_field name="linksbody1text" />" src="<txp:custom_field name="linksbody1url" />em-100.jpg"></a><br><a href="<txp:custom_field name="linksbody1url" />"><txp:custom_field name="linksbody1text" /></a></p></td>
 <txp:if_custom_field name="linksbody2url"><td width="17%"><p><a href="<txp:custom_field name="linksbody2url" />"><img alt="<txp:custom_field name="
 linksbody2text" />" src="<txp:custom_field name="linksbody2url" />em-100.jpg"></a><br><a href="<txp:custom_field name="linksbody2url" />"><txp:custom_field name="linksbody2text" /></a></p></td></txp:if_custom_field>
 <txp:if_custom_field name="linksbody3url"><td width="17%"><p><a href="<txp:custom_field name="linksbody3url" />"><img alt="<txp:custom_field name="
 linksbody3text" />" src="<txp:custom_field name="linksbody3url" />em-100.jpg"></a><br><a href="<txp:custom_field name="linksbody3url" />"><txp:custom_field name="linksbody3text" /></a></p></td></txp:if_custom_field>
 <txp:if_custom_field name="linksbody4url"><td width="17%"><p><a href="<txp:custom_field name="linksbody4url" />"><img alt="<txp:custom_field name="
 linksbody4text" />" src="<txp:custom_field name="linksbody4url" />em-100.jpg"></a><br><a href="<txp:custom_field name="linksbody4url" />"><txp:custom_field name="linksbody4text" /></a></p></td></txp:if_custom_field>
 <txp:if_custom_field name="linksbody5url"><td width="17%"><p><a href="<txp:custom_field name="linksbody5url" />"><img alt="<txp:custom_field name="
 linksbody5text" />" src="<txp:custom_field name="linksbody5url" />em-100.jpg"></a><br><a href="<txp:custom_field name="linksbody5url" />"><txp:custom_field name="linksbody5text" /></a></p></td></txp:if_custom_field> 
 <td width="100%"></td></tr></table></div>
</txp:if_custom_field>

Last edited by ingleslenobel (2014-10-29 13:49:32)

Offline

#11 2014-10-29 13:50:38

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: [SOLVED] if exist 'blocs'

There’s a Textile link below each textarea for posting, once there see “block modifier”. (Edit: Ah, question removed, see “Working now” ;)

Last edited by uli (2014-10-29 13:52:27)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

Board footer

Powered by FluxBB