Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-04-17 15:44:13

countytime
Member
Registered: 2015-04-05
Posts: 10

Excerpt only on front page, and only if an excerpt exists

So based on the advice on this page, I tried this in the default article form:

<div itemprop="articleBody">
    <txp:if_article_list />
      <txp:if_excerpt />
        <txp:permlink>Read more</txp:permlink>
      <txp:else />
        <txp:body />
      </txp:if_excerpt />
    <txp:else>
      <txp:body />
    </txp:if_article_list>
  </div>

My goal was to say:

If it's a list page
     If an excerpt exists
        Show excerpt
     else
        Show Body
Else (not a list page)
    Show body

But what happens is the body is still always shown on the main page, and now in the article (the permalinked article), the excerpt and the body is shown. How would I go about this? I want to show the excerpt instead of the body on the main page, if an excerpt exists.

Offline

#2 2015-04-17 15:46:31

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

Re: Excerpt only on front page, and only if an excerpt exists

countytime wrote #290079:

<txp:if_article_list />

Did you mean to self-close this conditional tag? And the <txp:excerpt>? And…


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

#3 2015-04-17 16:12:36

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

Re: Excerpt only on front page, and only if an excerpt exists

Try

<div itemprop="articleBody">
    <txp:if_article_list>
      <txp:if_excerpt />
        <txp:permlink>Read more</txp:permlink>
      <txp:else />
        <txp:body />
      </txp:if_excerpt>
    <txp:else>
      <txp:body />
    </txp:if_article_list>
  </div>

Reminder not to procrastinate. Stef picked it up in the previous post.

Last edited by colak (2015-04-17 16:13:45)


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

Offline

#4 2015-04-17 16:27:26

countytime
Member
Registered: 2015-04-05
Posts: 10

Re: Excerpt only on front page, and only if an excerpt exists

I’m confused about which tags I should be closing. The previous post says if_article_list shouldn’t be closed, but yours says it should. I just tried again and this time nothing showed up on their the article or the main page.

Last edited by countytime (2015-04-17 16:27:49)

Offline

#5 2015-04-17 17:30:22

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: Excerpt only on front page, and only if an excerpt exists

It should not be closed since it is closed by the </txp:if_article_list> tag, same for <txp:if_excerpt>

Corrected version of colak’s post

<div itemprop="articleBody">
    <txp:if_article_list>
      <txp:if_excerpt>
        <txp:permlink>Read more</txp:permlink>
      <txp:else />
        <txp:body />
      </txp:if_excerpt>
    <txp:else />
      <txp:body />
    </txp:if_article_list>
  </div>

Last edited by MattD (2015-04-17 17:31:11)


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#6 2015-04-17 17:34:53

countytime
Member
Registered: 2015-04-05
Posts: 10

Re: Excerpt only on front page, and only if an excerpt exists

The result of that is to remove everything except for the headlines from both the main page and the article view. The “Read more” link doesn’t show up either.

I’m not sure what’s going wrong here, since yours looks like it should work to me. At all conditions either the body or “Read more” should show up; there should be no condition where nothing shows up.

Offline

#7 2015-04-17 18:30:38

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

Re: Excerpt only on front page, and only if an excerpt exists

countytime wrote #290088:

The result of that is to remove everything except for the headlines from both the main page and the article view. The “Read more” link doesn’t show up either.

Please look at the page code you’re using (also think of forms that are called from there). It’s likely you self-closed one more container tag or something similar.

Also, as Bloke pointed to before: It doesn’t make sense to me that you never use the excerpt tag but check for an excerpt.

Edited to add reference.

Last edited by uli (2015-04-17 18:33:30)


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

Offline

#8 2015-04-17 19:02:25

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

Re: Excerpt only on front page, and only if an excerpt exists

I corrected the code above. Apologies for confusing you.


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

Offline

#9 2015-04-21 13:42:17

countytime
Member
Registered: 2015-04-05
Posts: 10

Re: Excerpt only on front page, and only if an excerpt exists

colak wrote #290098:

I corrected the code above. Apologies for confusing you.

One of the else tags is escaped and the other isn’t. Still kinda confused.

Offline

#10 2015-04-21 13:52:20

countytime
Member
Registered: 2015-04-05
Posts: 10

Re: Excerpt only on front page, and only if an excerpt exists

That’s a typo, I mean to print the excerpt.

Since everything else on the page works fine, including conditionals right above this, I don’t see how it could be something broken somewhere else on the page.

<div itemprop="articleBody">
  <txp:if_individual_article>
    <txp:body />
  <txp: else />
    <txp:if_excerpt>
      should be excerpt here
      <txp:excerpt />
    <txp:else />
      <txp:body />
    </txp:if_excerpt>
  </txp:if_individual_article>
</div>

Not only that, but the “should be excerpt here” doesn’t show up either, and neither does the body. Just the title.

Last edited by countytime (2015-04-21 14:08:12)

Offline

#11 2015-04-21 14:12:19

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

Re: Excerpt only on front page, and only if an excerpt exists

You have some syntax errors in there (that were not in the original post, though there were other errors there). It should read as follows:

<div itemprop="articleBody">
  <txp:if_individual_article>
    <txp:body />
  <txp:else />
    <txp:if_excerpt>
      should be excerpt here
      <txp:excerpt />
    <txp:else />
      <txp:body />
    </txp:if_excerpt>
  </txp:if_individual_article>
</div>

It won’t work with <txp: else /> or with <else />. It has to be@<txp:else />@ with a txp: in front, no space in-between and a closing /> because it’s not a containing tag. You also resolved the lack of the excerpt tag that others mentioned above.

EDIT: I see you’ve edited the second instance while I was writing and added the missing txp:. Check that what you post here does exactly correspond to what you have in the form.


TXP Builders – finely-crafted code, design and txp

Offline

#12 2015-04-21 14:21:08

countytime
Member
Registered: 2015-04-05
Posts: 10

Re: Excerpt only on front page, and only if an excerpt exists

Ok, this is solved. I actually got it while you were posting the same thing.

The problem was a single space in the else tag. The final, working code, is

<div itemprop="articleBody">
  <txp:if_individual_article>
    <txp:body />
  <txp:else />
    <txp:if_excerpt>
      <txp:excerpt />
    <txp:else />
      <txp:body />
    </txp:if_excerpt>
  </txp:if_individual_article>
</div>

Offline

Board footer

Powered by FluxBB