Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Different info on different articles_id in a sidebar?
Bloke wrote #279239:
EDIT: ah, hang on. No, I see now that you want to display different content depending on the article. In that case, yes, gaekwad and sprinkworks are offering the right advice and you can ignore my rambling above. If you want to get clever, you can start messing with using txp:variables to hold stuff, but I’ll save that example for if you find that the custom fields solution doesn’t meet your needs.
Not clever enough to mess with variables yet. And I dont see how I connect custom_field with article_id=“1, 2, 3 “ sidebars.
<txp:if_custom_field name="info">
<txp:custom_field name="info" />...
So every article has this custom field… How do I show article_id 1 custom_field on article_id 1 sidebar and article_id 2 custom_field on article_id 2 sidebar?
Last edited by admi (2014-02-25 16:26:04)
Offline
Re: Different info on different articles_id in a sidebar?
admi wrote #279241:
How do I show article_id 1 custom_field on article_id 1 sidebar and article_id 2 custom_field on article_id 2 sidebar?
Custom fields are per-article fields. You define them once (in Admin->Advanced Preferences) and then in each article on the Write panel, you define what value they hold. So if you are viewing article ID 1, you get article ID 1’s body, title, and custom field value.
In your case you’d define one called location
. In your ‘paris’ article you’d set the custom field to ‘Paris’. In your template, you then need to make sure the <txp:custom_field name="location">
tag appears inside your <txp:article>
tag. So, somewhere in your default Form (presumably) inside the <div id="sidebar">
block.
If you try to use the custom field tag outside an article tag (i.e. Textpattern is not in what we term individual article context) then it can’t fetch the custom field associated with the current article. So you may need to rejig your article page template for that section to make sure your sidebar is being rendered from inside an article tag.
If you could post some code you’ve tried (Page/Form), that might help us help you out. I might still have not quite grasped what you’re trying to do here…
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
Re: Different info on different articles_id in a sidebar?
Bloke wrote #279243:
Custom fields are per-article fields. You define them once (in Admin->Advanced Preferences) and then in each article on the Write panel, you define what value they hold. So if you are viewing article ID 1, you get article ID 1’s body, title, and custom field value.
In your case you’d define one called
location
. In your ‘paris’ article you’d set the custom field to ‘Paris’. In your template, you then need to make sure the<txp:custom_field name="location">
tag appears inside your<txp:article>
tag. So, somewhere in your default Form (presumably) inside the<div id="sidebar">
block.If you try to use the custom field tag outside an article tag (i.e. Textpattern is not in what we term individual article context) then it can’t fetch the custom field associated with the current article. So you may need to rejig your article page template for that section to make sure your sidebar is being rendered from inside an article tag.
If you could post some code you’ve tried (Page/Form), that might help us help you out. I might still have not quite grasped what you’re trying to do here…
I know how to use custom_fileds. But I can not paste stuff with <div>, <p> and other html-code into a custom field. Also it is difficult to locate to find what article custom field belongs. But article id is well seen in the list.
I achieved what I want and without any error warning through this in the page form archive connected with section About
<txp:if_article_list>
<txp:output_form form="RIGHTSIDEBAR" /> - for common articles
<txp:else />
<txp:if_article_id id="6">
<txp:output_form form="RIGHTSIDEBAR-for-Berlin" /> - right side bar for article id 6
<txp:else />
<txp:output_form form="RIGHTSIDEBAR" /> - for the rest articles in section About
</txp:if_article_id>
</txp:if_article_list>
But I need to add 2 more <txp:if_article_id id=”“> for another 2 articles from section about. Custom_fields cannot be used, they do not take html code.
Offline
Re: Different info on different articles_id in a sidebar?
admi wrote #279255:
I know how to use custom_fileds. But I can not paste stuff with <div>, <p> and other html-code into a custom field.
You can but you have to use the escape attribute. ie <txp:custom_field name="someName" escape="" />
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: Different info on different articles_id in a sidebar?
Well! Finally I got a revelation! I remembered this code from the default txp 4.5 head:
<txp:if_search>
<meta name="robots" content="none">
<txp:else />
<txp:if_category>
<meta name="robots" content="noindex, follow, noodp, noydir">
<txp:else />
<txp:if_author>
<meta name="robots" content="noindex, follow, noodp, noydir">
<txp:else />
<meta name="robots" content="index, follow, noodp, noydir">
</txp:if_author>
</txp:if_category>
</txp:if_search>
And by analogy tried this:
<txp:if_article_list>
<txp:output_form form="RIGHTSIDEBAR" />
<txp:else />
<txp:if_article_id id="6">
<txp:output_form form="RIGHTSIDEBAR-for-Berlin" />
<txp:else />
<txp:if_article_id id="18">
<txp:output_form form="RIGHTSIDEBAR-for-Moscow" />
<txp:else />
<txp:if_article_id id="19">
<txp:output_form form="RIGHTSIDEBAR-for-Minsk" />
<txp:else />
<txp:output_form form="RIGHTSIDEBAR" />
</txp:if_article_id>
</txp:if_article_id>
</txp:if_article_id>
</txp:if_article_list>
It works ok at first look, hope at second look as well. No error warnings. Tomorrow I will post another question as for using <txp:if_article_id>
Last edited by admi (2014-02-25 19:35:29)
Offline
Re: Different info on different articles_id in a sidebar?
admi wrote #279255:
I know how to use custom_fileds. But I can not paste stuff with <div>, <p> and other html-code into a custom field. Also it is difficult to locate to find what article custom field belongs. But article id is well seen in the list.
OK, sorry, didn’t mean to come across patronising. But as colak points out you can use HTML in custom fields (subject to the current 255 character limit), and if you are concerned about visibility of custom field data on the Write panel, you can use bot_write_tab_customize to change the layout.
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
Re: Different info on different articles_id in a sidebar?
Bloke wrote #279261:
OK, sorry, didn’t mean to come across patronising. But as colak points out you can use HTML in custom fields (subject to the current 255 character limit), and if you are concerned about visibility of custom field data on the Write panel, you can use bot_write_tab_customize to change the layout.
That’s Ok. I dont mind patronising from the guys who know more than I do. What about the code that I used above? From your and TXP point of view does it look all right?
Offline
Re: Different info on different articles_id in a sidebar?
The concern with the code you posted would be what if in the future you need a “Right Sidebar for New Mexico”. You’ll need a new form to go with that article and you’ll need a new if_article_id tag.
Custom fields would allow you to store the sidebar info with each article.
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: Different info on different articles_id in a sidebar?
MattD wrote #279265:
The concern with the code you posted would be what if in the future you need a “Right Sidebar for New Mexico”. You’ll need a new form to go with that article and you’ll need a new if_article_id tag.
Custom fields would allow you to store the sidebar info with each article.
well, i will try both ways. I like article_ids cause articles are well seen in the article list and it is logical continuation of if_section, if_category, if_article_list, if_individual_article…. also how do you edit stuff in several paragraphs in a custom_field if needed – that’s a real hell.
Offline
Re: Different info on different articles_id in a sidebar?
admi wrote #279263:
What about the code that I used above? From your and TXP point of view does it look all right?
Sure, it’ll work. Because your first else statement makes sure Txp is in individual article context so it can access the article data. But it’s not very clean, and will be hard to maintain in future, as MattD says.
That’s why we’re trying to figure out what, exactly, you want to show in the sidebar — what sort of markup — because I still think you’ll be better off collecting the content if at all possible, and keeping the presentation separate in the template. Mixing them in this manner works fine, but you may be able to save yourself quite a lot of conditional code and potential head scratching in six months’ time.
Anyway, let’s go back a step. You want article 6 to have a sidebar block that shows info about Berlin, article 18 to show a sidebar block about Moscow and article 19 to show a sidebar about Minsk, right? At least, that’s all for now.
The custom field approach will work, but is perhaps overkill because you only want the content in those three articles and don’t want to saddle all your articles with empty custom data. I think I see your reservation about custom fields now, but for completeness let’s work through it anyway. Assuming you want to display the office’s Location, a brief Description and a bunch of Images in the sidebar, you’d create two custom fields called location
and description
respectively, and edit the articles so all your content is co-located with the article to which it refers, using Article Image to hold the list of image IDs.
In your archive template you’d then do this where your block of code is above:
<div id="sidebar">
<txp:if_individual_article>
<txp:output_form form="article-sidebar" />
<txp:else />
<txp:output_form form="list-sidebar" />
</txp:if_individual_article>
</div>
So, landing pages get your list-sidebar
displayed and all articles get article-sidebar
. Fine, but we need to make sure that only those three articles get the content. Since only those three articles have custom field content, you can use some conditional magic to check, inside the article-sidebar
Form:
<txp:if_custom_field name="location">
<h3>Office: <txp:custom_field name="location" /></h3>
<p><txp:custom_field name="description" /></p>
<txp:hide> Add any images </txp:hide>
<txp:images wraptag="ul" break="li">
<txp:thumbnail />
</txp:images>
<txp:else />
<txp:hide> Location (and, by inference, Description) not set so default to list sidebar </txp:hide>
<txp:output_form form="list-sidebar" />
</txp:if_custom_field>
Job done.
But as I alluded earlier, that’s going to pollute your custom field pool for the sake of three articles. Your approach puts content in multiple Forms which clutters things up. So, in the interests of content separation, or at least trying to keep things grouped, how about we ditch the custom field / one-Form-per-article idea and instead be more creative in your article-sidebar
Form:
<txp:hide> BERLIN </txp:hide>
<txp:variable name="sidebar-6">
<h3>Office: Berlin</h3>
<p>Berlin is a vibrant city full of people blah blah...</p>
<txp:output_form form="image-sidebar">5, 3, 28, 17, 39</txp:output_form>
</txp:variable>
<txp:hide> MOSCOW </txp:hide>
<txp:variable name="sidebar-18">
<h3>Office: Moscow</h3>
<p>Moscow is a vibrant city full of people blah blah...</p>
<txp:output_form form="image-sidebar">6, 11, 25</txp:output_form>
</txp:variable>
<txp:hide> MINSK </txp:hide>
<txp:variable name="sidebar-19">
<h3>Office: Minsk</h3>
<p>Minsk is a vibrant city full of people blah blah...</p>
<txp:output_form form="image-sidebar">22, 1, 13, 72</txp:output_form>
</txp:variable>
<txp:hide> Only output one of the above variable blocks if it's been defined for the current article ID </txp:hide>
<txp:if_variable name='sidebar-<txp:article_id />'>
<txp:variable name='sidebar-<txp:article_id />' />
<txp:else />
<txp:output_form form="list-sidebar" />
</txp:if_variable>
And in image-sidebar
you can take the comma-separated list of image IDs and inject them into an attribute using <txp:yield />
:
<txp:images id='<txp:yield />' wraptag="ul" break="li">
<txp:thumbnail />
</txp:images>
OK, the content isn’t tied directly to the articles, but at least it’s all contained in one Form and if you ever need to extend it, there’s only one extra place to look where all the content is collected. You could abstract the textual ‘location and description’ part out to sub-Forms too if you wished using the same yield idea. Depends how far you want to go.
Does that give you something to work with? (EDIT: none of the above is tested, btw, just off the top of my head)
Last edited by Bloke (2014-02-25 21:32:47)
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
Re: Different info on different articles_id in a sidebar?
Bloke’s recommendation is a good one and removes most of my concerns. Especially if you don’t have a client or some other user who needs to update these pieces of content.
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: Different info on different articles_id in a sidebar?
MattD wrote #279273:
Bloke’s recommendation is a good one and removes most of my concerns. Especially if you don’t have a client or some other user who needs to update these pieces of content.
Thanx everybody for shedding some light on this important issue. I think it should be posted in http://txptips.com
How about this? I need to show a certain left sidebar menu on the above pages whereas on all the of pages there will be a different menu. I use this code:
<txp:if_article_list>
<txp:linklist break="li" category="leftmenu" limit="7" sort="linksort asc" wraptag="" />
<txp:else />
<txp:if_article_id id="6,18,19">
<txp:linklist break="li" category="contacts" limit="7" sort="linksort asc" wraptag="" />
<txp:else />
<txp:linklist break="li" category="leftmenu" limit="7" sort="linksort asc" wraptag="" />
</txp:if_article_id>
</txp:if_article_list>
Is this method rational enough?
Offline