Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2020-09-01 12:59:19

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

Re: Tag for static section on homepage only

I am using custom_fields instead of stickies. For this page for example, I am using a custom_field named c10, to separate current/featured blog posts from the rest. You can check how I have done it on github. Note that the name of the form I am using, sticky_form, is a legacy name from the time I was actually using sticky articles. I just find CFs easier to handle and manipulate:)


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

Offline

#26 2020-09-01 13:35:39

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Tag for static section on homepage only

gu wrote #325707:

As for the search problem, I am now discovering that I possibly did not include the full range of txp code that is needed.

By default txp uses search_results form to output search results, please check whether it exists. Also, putting the site in debug mode might help.

Offline

#27 2020-09-01 14:41:42

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

Re: Tag for static section on homepage only

etc wrote #325711:

Also, putting the site in debug mode might help.

Just wanted to add that, when the site is on debug mode, you will be able to see a tag trace, and possible errors, in the source code of the page your are trying to troubleshoot.


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

Offline

#28 2020-09-01 20:21:54

gu
Member
Registered: 2020-08-27
Posts: 59

Re: Tag for static section on homepage only

> edited: misspelled name
> edited again: I don’t see colak’s signature anymore. It said something to the effect of doing one’s best editing after pressing publish.

tl;dr Currently, I have what used to be the static pages displayed at the top of the articles ‘feed’ but they are also repeated further down. And this new solution has now garbled the way the page is displaying on mobile screens.

What a past few hours it has been (but very interesting: I try to encourage myself by saying that as I try to find the solution I am also learning new things).

- colak – I tried variations of your hack (and rejoiced at the boolean). Also – I just realised that your signature is my spirit animal.

- etc thank you for that suggestion – given the problems I’m now facing, I strongly suspect there is a problem with a bug. I guess it is because I am not using just the default page but also an article form because that made it possible for comments to only appear on articles and not on the home page.
But I do not know how to find bug mode and my cursory internet search did not help. (It is time for a break… but so hard to learn discipline to let these problems go in order to get the rest needed by human beings.)

In closing, and to dompt the tension I feel, I’d like to express the marvel I felt when looking at colak’s code when I realized that I understood some of it. I looked at the boolean solution which was just another way of the <txp:if_article_list> and <txp:if_article_list not> solution and thought: how beautiful this all is!

Last edited by gu (2020-09-01 20:27:17)


<!— space for hope —>

Offline

#29 2020-09-01 22:03:03

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

Re: Tag for static section on homepage only

You mentioned above that you’re using the “zero” theme, and while that gives you a clean slate to start with, it is also lacking some of the default txp forms (under Presentation › Forms) that Textpattern uses to display standard content.

I suspect that is why you see no search results when adding a search term. As etc mentioned, txp uses the search_results form to output search results unless you explicitly specify a form of your own.

Similarly, the individual article display (i.e. when the URL is site.com/section/article-name) uses the default form by default and the article_listing form for listing pages such as on the default page, a category filter or a section landing page. If you don’t have those forms in your theme (and don’t specify an alternative form of your own), you won’t see the expected output.

Those may also explain why you’re seeing no article body output when visiting an individual page.

sticky url not showing twice in a listing

sticky url not showing when you visit it

By default the standard txp:article tag uses status="live" (as detailed in the docs). That means it will not display sticky articles.

For your article_list view on the homepage, you can use this to stop it showing twice. Your txp:article_custom id="4" status="sticky" will show it explicitly, but the txp:article tag further down will only show live articles.

If you want your sticky articles to be visitable via an url, you need to employ a trick in your individual_article case:

<txp:if_individual_article>
    <txp:article status="sticky" />
    <txp:article status="live" />
</txp:if_individual_article>

While this may at first seem illogical, because this code only kicks on an individual article page, it will use either one or the other tag, depending on the current article’s status.

If you are using a sticky article just to show some intro text (without a page to click through to), you don’t need this at all. See instead the container-tag example below.

the form="myform" attribute vs. no form vs. container tag usage.

You can use txp:article , txp:article_custom, and many other tags that use forms in different ways.

  • If you provide no form attribute at all, the tag will use a default form name. See the docs for the name of the form txp looks for.
  • If you provide a form="myform" attribute with a name of your own choosing, it will output the contents according to what you put in the myform form.
  • In cases where you just want some quick output once-only, you don’t have to define a form in every instance. Instead you can use the tag as a container like this:
<txp:article_custom id="4" status="sticky">
    <div class="intro-blurb">
        <txp:excerpt />
    </div>
</txp:article_custom>

debugging mode

You can switch to debugging mode by visiting Admin › Preferences › Site Preferences and looking for the Production Status dropdown. Choose “Debugging” and click Save to change the status. The different production statuses are described in the docs here.


TXP Builders – finely-crafted code, design and txp

Offline

#30 2020-09-02 14:51:30

gu
Member
Registered: 2020-08-27
Posts: 59

Re: Tag for static section on homepage only

> edit: closing bracket. I am making this edit in a bid to teach myself how to reach “flow” (cf. Csikszentmihalyi) in commenting. At the moment I am still a little nervous about forums, which causes sloppiness. How did you all learn this etiquette, I wonder?

Thank you Jakob for your detailed post. I don’t know if I should stop posting here with responses (I honestly don’t know enough about the ways forums work, so if I overstay my welcome, please, someone let me know, especially because I am such an ignoramus and have extended the scope of my original question). I’ve decided, for now, to share further thoughts in case they are relevant to development.
  • Yes, I am working on Zero but to be clear I did fill in a Form with code for the default page – this included the txp to retrieve body (with heading) and the txp for comments and relevant posts.
  • It turns out the search function works but with limited results. For example, I had several articles with the word “article” in the headline – searching for “article” led to positive results. But searching for words within posts was not effective. I wonder if this is because I do not know how to include the “aria” code.
  • The code snippet that you were so kind to share was also able – like the other hack I invented for myself (making the articles on the home page show only those posts destined for the homepage [using the boolean custom_article attribute]) – to list those articles successfully on the homepage – but with the same problem of the URL no longer leading to the content written in the body of that article. I tried different placements of the last line of that code but in all cases, the URL of the article did not deliver the body.

If anyone is following along with my story and using my woes for entertainment :), I actually totally rewrote the code for the site yesterday (! time suck) in a much cleaner way, but this led to new problems. I have another site with the old code on it (also not currently in official use), so I did not lose the satisfaction of at least having the appearance that I can make something that looks good but am trying to develop good habits even if this means starting all over again. An example of why: in the version that looks good, my css had .entries except for body, which, when prefaced as .body would totally throw off the page appearance.

I consider that must surely be because of poor programming and since I want to share my Simple Txp (I have no illusions at how little of a contribution this is! but for me it would be a great achievement) I want to present something that avoids any errors I can see. As a beginner, I know there will likely be errors I cannot see but I am trying to avoid that by reading up on every code snippet I use.

A final (working) thought: txp is the enthymeme to syllogisms in code. Ok, off to work on the site now. Thank you forum for all of your kindness and support.

Last edited by gu (2020-09-02 15:01:28)


<!— space for hope —>

Offline

#31 2020-09-02 16:00:03

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

Re: Tag for static section on homepage only

I don’t know if I should stop posting here with responses…

Oh no, I didn’t mean to imply that at all. Please post as much as you like.

I am just back from a break away and was reading through posts and mopping up loose items.

I actually totally rewrote the code for the site yesterday in a much cleaner way …

That sounds to me like a perfectly normal learning process of iteration, trial and error and improvement.

the search function works but with limited results. For example, I had several articles with the word “article” in the headline – searching for “article” led to positive results. But searching for words within posts was not effective. I wonder if this is because I do not know how to include the “aria” code.

That sounds unusual. Searches should match titles and body content alike. The aria code has no effect on that, so there must be another reason.

If you mean you’re not seeing the search result in the body, it may be because you’re missing the txp:search_result_excerpt tag, which shows you matches in that page. See the docs for search tags.

… the same problem of the URL no longer leading to the content written in the body of that article. I tried different placements of the last line of that code but in all cases, the URL of the article did not deliver the body.

The code you had above was probably for the page template you are using for the home (default) section. But your article will be assigned to another section, and when you click the url it will go to site.com/your-section/article-url-title.

Textpattern will see “your-section” in the URL and look up which page template you have assigned to display articles assigned to that section. If you have a different page template set under Presentation › Sections, it will use that page template. That should help you find how it’s displaying articles.

It’s also useful to know that txp:article responds to the context of the url. It uses the form specified in the listform="..." attribute for article list pages (e.g. section landing pages or category or author pages) and the form specified in form="…" for the individual article display. If you don’t specify those, it uses the article_listing and default forms.

In most straightforward cases, you don’t need to additionally use txp:if_article_list or txp:if_individual_article unless you want some specific behaviour that overrides the normal pattern. This means, take care when placing your txp:article tag inside an if_…-condition block, as you will find it never gets called when the condition doesn’t apply. That’s why etc placed it at the very bottom of his code above.

(By contrast article_custom ignores the context given in the url, so you can use it to explicitly show an article.)

Finally, another really simple way to avoid your templates getting too complex and having to take into account too many different situations is to make one page template for the homepage (section = default) and another for your section … and another for a static page … and so on.


TXP Builders – finely-crafted code, design and txp

Offline

#32 2020-09-02 17:41:46

gu
Member
Registered: 2020-08-27
Posts: 59

Re: Tag for static section on homepage only

Thank you Jakob – and I wonder if you might want to add that information to one of the learning pages since you have explained it so clearly.
I have had to take a break from my site for work obligations but I am so looking forward to trying this out and thinking about it some more.
I would not have advanced as I have without the help of the forum. This teaching is a great gift and one that I want to respect and not take for granted. I will post again when I have tried the solution. Thank you Jakob and thanks to the other forum members who have been so generous with your time (colak, etc, gaekwad)!


<!— space for hope —>

Offline

#33 2020-09-04 15:24:16

gu
Member
Registered: 2020-08-27
Posts: 59

Re: Tag for static section on homepage only

>edited to change code to how I now have it
This is to say that Jakob’s solution was effectively implemented re. the default page setup. The article list is now changing blog posts beneath the posts I always want on display on the homepage. Also, respective URLs now display page content.

Because I do not want to clog up the textpattern front page with n00b questions, I am going to ask for help again here – pertaining to the search txp tags. I tried to find the solution myself but was unable to.

Would anyone be able to help me with why the following code is not working:
<h2> Search results <q><txp:search_term /></q> </h2> <p>These articles match your search request:</p> <txp:search_result_excerpt /> <txp:else /> <p>Sorry, we were not able to find a page matching your search request <q><txp:search_term /></q>.</p> <txp: else /> <h2> Articles in category <q><txp:category /></q> </h2> <txp:article form="article_listing" />
Is it because I did not fill out a Form? I was looking at four-point-nine and noticed there was a section on search-input. I do not have such a thing on my site as it is.
Thank you!

Last edited by gu (2020-09-04 17:34:43)


<!— space for hope —>

Offline

#34 2020-09-04 15:49:14

gu
Member
Registered: 2020-08-27
Posts: 59

Re: Tag for static section on homepage only

…actually, the problem is deeper. That code snippet above is now interrupting how the category results display. I have a list of categories always visible at the top of every page. Clicking on them now leads to the “sorry” message from the search code above, followed by the header Articles in category “”, and then a dead repeat of the name of the category, with no mention of articles in that category.


<!— space for hope —>

Offline

#35 2020-09-04 15:50:50

gu
Member
Registered: 2020-08-27
Posts: 59

Re: Tag for static section on homepage only

Oh wait – I will try Jakob’s solution from above and create a new Page for category… Sorry forum, just thought of that now.


<!— space for hope —>

Offline

#36 2020-09-04 19:01:17

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

Re: Tag for static section on homepage only

Hi, The best and easiest way is to have the code in the search_results form.


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

Offline

Board footer

Powered by FluxBB