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: 3,934
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: 44

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: 44

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: 44

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: 44

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: 8,269
Website

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.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
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: 44

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: 44

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: 8,269
Website

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.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
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: 44

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

Board footer

Powered by FluxBB