Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,218
Website GitHub

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,395
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

#37 2020-09-04 19:09:08

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

Re: Tag for static section on homepage only

Thank you Yiannis. I will focus on that now. I also thought I needed to create a section and page for categories, but either I did that wrong or it is not necessary. Greetings!


<!— space for hope —>

Offline

#38 2020-09-05 09:58:49

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

Re: Tag for static section on homepage only

New process, ending with a key observation, if anyone cares to help with my attempt to make the search function work and have category URLs list the articles that are contained within them:
  • I made a search page with code like other pages except with this:
    <main> <txp:if_search> <h2><txp:permlink><txp:title /></txp:permlink></h2> <txp:search_result_excerpt /> </txp:if_search> </main>
  • I also made the search section with this input
    search_results
    search_results
    Zero
    search
    default
    default
    no no no
  • I had also (either with that section existing or not, just to try to learn through practice) included variations on search_results and search_input forms, always stored in miscellaneous.
  • An example form:
    <h2><txp:permlink><txp:title /></txp:permlink></h2> <txp:if_individual_article> <txp:body /> <div class="search-results"> <h2> Search results <q><txp:search_term /></q> </h2> <p>These articles match your search request:</p> <h3> <txp:permlink> <txp:title /> </txp:permlink> </h3> <p> <txp:search_result_excerpt hilight="p" limit="15" /> | <txp:permlink> <txp:permlink /> </txp:permlink> | <txp:posted /> </p> <txp:else /> <p>Sorry, we were not able to find a page matching your search request <q><txp:search_term /></q>.</p>
  • But I also tried versions like this:
    <txp:article limit="10" pgonly="1" /> <h2><txp:search_result_count text="search results" /> for "<txp:page_url type="q" />"</h2> <txp:article limit="10" /> <p><txp:older>&raquo; Next results &raquo;</txp:older></p> <p><txp:newer>&laquo; Newest results &laquo;</txp:newer></p> <txp:output_form form="search" />
  • Sometimes prefaced with variations of this:
    <h2><txp:permlink><txp:title /></txp:permlink></h2> <txp:search_result_excerpt />
  • None of that helped.
  • I appreciate this looks like I am playing coding lottery but this is because what I think I know is often wrong.
  • Maybe all I am missing is an anchor somewhere?
  • My best results were trying to include the code to search and categories on my default page – but because of how I have that set up (with too may txp_ifs), I was advised to search for a workaround and use a form. Maybe I just don’t know how to use the form correctly but I did randomly copy-paste form code from 4.9 and the ideal website forms to see if I could learn something from that code implementation (and see if it would work: it did not).
  • Most importantly: when I view the page source for searches or for when I click on the categories (note: my pages always have a nice list of categories displayed at the top, under the logo and search bar also always there), the <main> section always contains <txp:articles /> and never anything else even though I try to point the search and categories elsewhere. I am not only using a default page and have tried creating a category page with its own section (which seemed like an obvious solution to the problem) but that did not work – or, maybe I did not put the appropriate code on the page with its section.

<!— space for hope —>

Offline

#39 2020-09-05 15:58:51

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

Re: Tag for static section on homepage only

You have : … <txp:if_individual_article> <txp:body /> <div class="search-results"> <h2> Search results <q><txp:search_term /></q> </h2> <p>These articles match your search request:</p>

Searches cannot be returned within an if_individual_article context, instead, they need to reside within an if_search one. Also, and please someone correct me if there are better methods, the tree should be something like.

<txp:if_article_list>
	<txp:if_section name='<txp:section />'>
		<txp:if_search>
			<txp:if_search_results>
			<txp:else />
			<p>no search results</p>
			</txp:if_search_results>
		</txp:if_search>
		<txp:else />
		<txp:if_category>
		</txp:if_category>
		<txp:else />
		</txp:if_search>
	</txp:if_section>
</txp:if_article_list>
<txp:if_individual_article>
</txp:if_individual_article>

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

Offline

#40 2020-09-06 11:44:33

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

Re: Tag for static section on homepage only

Thank you for your reply Yiannis, which I am grateful for as a form of encouragement. Above all, thank you for your time and input. I wanted to stop by to say that before getting back to working on the site. Have a lovely day!


<!— space for hope —>

Offline

#41 2020-09-06 15:04:23

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

Re: Tag for static section on homepage only

gu wrote #325813:

Thank you for your reply Yiannis, which I am grateful for as a form of encouragement. Above all, thank you for your time and input. I wanted to stop by to say that before getting back to working on the site. Have a lovely day!

One good way of designing with txp is to do it without fluff. That is, use as few html elements as possible and no css. Once you know that the tags work as intended in the pages you wish them to appear, you can start adding the rest. In other words, do your app first and then work on the user interface.


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

Offline

#42 2020-09-06 15:49:21

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

Re: Tag for static section on homepage only

Thank you Yiannis – I am on that very wavelength and have deleted things. Also, I am making progress!

I see I made many errors in my second to last post… I am tempted to correct it but above all want to say: thanks for the encouragement. A little wind for the solitary sail (not so solitary!)


<!— space for hope —>

Offline

#43 2020-09-06 21:41:41

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

Re: Tag for static section on homepage only

>major edit follows, throughout post as I thought I had questions, but then found I was able to answer them myself, largely thanks to the input in this thread which I have revisited multiple times.

This post was once about making it to debug mode once I was sure, based on double-checking the advice here and on the tag explanations, that what I wrote was based on support.

I had a problem with <txp:article_custom frontpage=“1” sort=“Section desc” /> which got the warning Closing tag without corresponding opening tag: </txp:if_individual_article>.

I had problems caused by div class with txp combos. <txp:search_input /> appeared as a ‘form not found’ though it was on the page.

Output forms are magic. Thanks to Yiannis for continuing to recommend them – that must have been lodged in my brain to help associate the forms with these problems, even though I began by pursuing solutions based on wraptags, thinking the problem was caused by html class divs.

In conclusion, I do not think that I know how to use forums. It is too tempting for a person like me to think aloud and, in this instance, not be able to judge where or what is deemed useful to say because I am just so new at both forums and coding (to be fair, I did a little bit a while ago, but there are different levels of beginners). I can’t wait to get over this beginner’s slump but thank you for contributing to what is a safe community to grow. If I succeed in growing, you will be the village that raised me :)

I would really like to clean up previous comments, but maybe they are a source of fond memories for some as they remember their own first steps, or a prompt for a gentle chortle. But if anyone thinks I could scrap some of them to tidy up this thread I would be more than happy to. I cannot believe how even I myself can see just how messy they are in such a short time (though inclusive of both nights and days). I hope to have my little program to share soon, but I am not quite done. Cheers to this most lovely forum.

Last edited by gu (2020-09-07 10:32:57)


<!— space for hope —>

Offline

#44 2020-09-07 11:14:23

zero
Member
From: Lancashire
Registered: 2004-04-19
Posts: 1,475
Website

Re: Tag for static section on homepage only

I rarely reply re technical things on this forum, usually leaving it to those who are very clear about tags and coding, but maybe others are very busy so I’ll have a go, gu, and hope I don’t confuse you.

gu wrote #325824:

I had a problem with <txp:article_custom frontpage=“1” sort=“Section desc” /> which got the warning Closing tag without corresponding opening tag: </txp:if_individual_article>.

<txp:if_individual_article> ends with </txp:if_individual_article> and the warning simply states either <txp:if_individual_article> is missing, or perhaps you spelt it wrong or there’s an extra > or something like that.

I had problems caused by div class with txp combos. <txp:search_input /> appeared as a ‘form not found’ though it was on the page.

Perhaps you had <txp:search_input /> on the page, but does it exist in your list of forms? Have you changed its name, perhaps to search-input or something like that?

In conclusion, I do not think that I know how to use forums….

You’re doing fine, don’t worry about it, we all make mistakes and say things that embarrass us later that we wish we’d never said. But at the time we didn’t know as much as we know now, or perhaps we weren’t having a good day. We’re all human beings on here (except developers who are super-human pretending to be quite normal :) so we’ve all been through stuff similar to your experience. I’m looking forward to seeing your little project, it sounds intriguing.


Dozy P My attempt at music

Offline

#45 2020-09-07 13:00:56

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

Re: Tag for static section on homepage only

Hi Zero, so appreciate your message! Truly!!!

In the mean time, here is some news: I can’t believe it but I finished my little site! No more bugs!

Since I have found WC3 markup validation to kind of be like a Magic 8 Ball: sometimes revealing new problems simply by entering the website address at a different time of the day, I will let the site rest and then recheck it. Then I’ll try to check for redundancies. And then I’ll share it.

I am reading the Themes: Creating, Using, Sharing page now and expect that will be a learning process too but I hope to have this out by next week.

Thank you for being so supportive of “beginner’s mode” :)


<!— space for hope —>

Offline

Board footer

Powered by FluxBB