Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-03-24 01:01:56

lythande
Member
Registered: 2009-09-08
Posts: 202
Website

some strange errors with individual article and excerpt

Hi,

I have some articles with excerpt and wish to show at the home-page only title and excerpt. In the individual article should show title, excerpt, body, comments.

When I changed the code to make it so (it is already working on another website), the main navigation disappears and only “start” is seen. Remember the article and it is only the excerpt displayed as desired. Very strange…

page code:

<div class="wrapper">
    <div class="container">

      <!-- left (main) column -->
      <div role="main">

      <!-- is this search result page? also omits the pagination links below (uses pagination format within search_results.article.txp instead) -->
      <txp:if_search>

        <h1><txp:text item="search_results" /></h1>
        <txp:output_form form="etc_static_search_results" />

      <txp:else />

        <!-- else is this an article category list? -->
        <txp:if_category>

          <h1><txp:text item="category" /> <txp:category title="1" /></h1>
          <txp:article form="article_listing" limit="5" />

        <txp:else />

          <!-- else is this an article author list? -->
          <txp:if_author>

          <h1><txp:text item="author" /> <txp:author /></h1>
          <txp:article form="article_listing" limit="5" />

          <txp:else />

            <!-- else display articles normally -->
            <txp:article_custom id="22,4,3,6,7" /> <!-- links by default to form: 'default.article.txp' unless you specify a different form -->

          </txp:if_author>
        </txp:if_category>

<txp:output_form form="pagination" />

      </txp:if_search>

      </div> <!-- /main -->

form default

<article role="article" itemscope itemtype="http://schema.org/Article">

<!-- if not an individual article then make the title h1 a link -->
<txp:if_individual_article>
  <h1 itemprop="name"><txp:title /></h1>
<txp:else />
  <h1 itemprop="name"><a href="<txp:permlink />" itemprop="url"><txp:title /></a></h1>
</txp:if_individual_article>

  <p class="small"><txp:hide><strong><txp:text item="posted" /></strong></txp:hide> Ver&ouml;ffentlicht am <time datetime="<txp:posted format='iso8601' />" itemprop="datePublished"><txp:posted /></time>
    <a href="<txp:permlink />#comments-head" title="<txp:text item='view' />&#8230;" itemprop="discussionUrl" itemscope itemtype="http://schema.org/UserComments"> <txp:text item="comments" /></a> 

<!-- if comments then display the number, if no comments then print 'none' -->
<txp:if_comments>
  <span itemprop="interactionCount"><txp:comments_count /></span>
<txp:else />
  <span itemprop="interactionCount"> 0 </span>
</txp:if_comments>

  </p>
  <div itemprop="articleBody">
  <txp:if_individual_article>
    <txp:output_form form="article-image" />
    <txp:excerpt />
    <txp:body />
  <txp:else />  
    <txp:output_form form="article-image" />
    <txp:excerpt />
  </txp:if_individual_article>
 <txp:hide><txp:output_form form="article-image" />
    <txp:body /></txp:hide> 
 </div>
  <div class="divider"></div>

 <p><txp:hide> <strong><txp:text item="author" /></strong> <span itemprop="author"><txp:author link="1" this_section="1" /></span> </txp:hide>

  <!-- only display categories if they are actually set for an article, otherwise omit -->
  <txp:if_article_category>
    <br><strong><txp:text item="category" /></strong> <span itemprop="keywords"><txp:category1 title="1" link="1" /><txp:if_article_category number="1"><txp:if_article_category number="2">, </txp:if_article_category></txp:if_article_category><txp:category2 title="1" link="1" /></span>
  </txp:if_article_category>
  </p>

<!-- if this is an individual article then add the comments section via form: comments_display.article.txp -->
<txp:if_individual_article>
  <txp:article form="comments_display" />
</txp:if_individual_article>

</article>

If I hide the code snippets

 <txp:if_individual_article>
    <txp:output_form form="article-image" />
    <txp:excerpt />
    <txp:body />
  <txp:else />  
    <txp:output_form form="article-image" />
    <txp:excerpt />
  </txp:if_individual_article>

and code snippets advertisement, which I hid under it, then the main navigation is back, but text is displayed in full.

form article-image:

<!-- set up a variable to check whether a image also has a caption associated with it... -->
<txp:variable name="caption" value='<txp:hide><txp:image_info type="caption" /></txp:hide>' />

<!-- ...now use that image caption and wrap img inside a figure with figcaption tags, otherwise just use a plain img tag -->
<txp:if_variable name="caption" value="">

<!-- image - overriding the width and height to let the image scale to fit parent container -->
  <p><txp:hide><txp:article_image width="0" height="0" /></txp:hide>
    <txp:if_article_image>
  <txp:images id='<txp:custom_field name="article_image" />' sort=' field(id, <txp:custom_field name=''article_image'' />)' break="">
    <txp:article_image />
    <figcaption itemprop="caption"><txp:image_info type="caption" /></figcaption>

  </txp:images>
</txp:if_article_image>
</p>

<txp:else />

  <figure itemscope itemtype="http://schema.org/ImageObject">

<!-- image - overriding the width and height to let the image scale to fit parent container -->
    <txp:hide><txp:article_image width="0" height="0" /></txp:hide>
   <txp:if_article_image>
  <txp:images id='<txp:custom_field name="article_image" />' sort=' field(id, <txp:custom_field name=''article_image'' />)' break="">
    <txp:article_image />
    <figcaption itemprop="caption"><txp:image_info type="caption" /></figcaption>

  </txp:images>
</txp:if_article_image>

<!-- you do not need to specify the attribute type="caption" as that is the default setting for <txp:image_info /> tag -->
    <figcaption itemprop="caption"><txp:image_info type="caption" /></figcaption>

  </figure>

</txp:if_variable>

Offline

#2 2015-03-24 13:47:53

lythande
Member
Registered: 2009-09-08
Posts: 202
Website

Re: some strange errors with individual article and excerpt

Very strange… I have copied the code from the form default to a new form with another name. “orte-artikel”
and change there only some code, not much and have my excerpts in the code. This works fine, without problems with navigation…

<article role="article" itemscope itemtype="http://schema.org/Article">

<!-- if not an individual article then make the title h1 a link -->
<txp:if_individual_article>
  <h1 itemprop="name"><txp:title /></h1>
<txp:else />
  <h1 itemprop="name"><a href="<txp:permlink />" itemprop="url"><txp:title /></a></h1>
</txp:if_individual_article>

  <p class="small">Ver&ouml;ffentlicht am <time datetime="<txp:posted format='iso8601' />" itemprop="datePublished"><txp:posted /></time> in 
  <!-- only display categories if they are actually set for an article, otherwise omit -->
  <txp:if_article_category>
    <txp:text item="category" /></strong> <span itemprop="keywords"><txp:category1 title="1" link="1" /><txp:if_article_category number="1"><txp:if_article_category number="2">, </txp:if_article_category></txp:if_article_category><txp:category2 title="1" link="1" /></span>
  </txp:if_article_category>
   - <a href="<txp:permlink />#comments-head" title="<txp:text item='view' />&#8230;" itemprop="discussionUrl" itemscope itemtype="http://schema.org/UserComments">  
<!-- if comments then display the number, if no comments then print 'none' -->
<txp:if_comments>
  <span itemprop="interactionCount"><txp:comments_count /></span>
<txp:else />
  <span itemprop="interactionCount"> 0 </span>
</txp:if_comments>
<txp:text item="comments" /></a>
  </p>

  <div itemprop="articleBody">
  <txp:if_individual_article>
    <txp:output_form form="article-image" />
    <txp:excerpt />
    <txp:body />
  <txp:else />  
    <txp:output_form form="article-image" />
    <txp:excerpt />
  </txp:if_individual_article>
 </div>
  <div class="divider"></div>

<!-- if this is an individual article then add the comments section via form: comments_display.article.txp -->
<txp:if_individual_article>
  <txp:article form="comments_display" />
</txp:if_individual_article>

</article>

Offline

Board footer

Powered by FluxBB