Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-03-07 13:08:05

azw
Member
Registered: 2007-01-29
Posts: 279

How to NOT show a link if the link is the same as the current page?

I show a list of editorial articles in a sidebar. This appears on every page. These editorials are the individual articles in the editorial section of the site.

The list is created with this statement: <txp:article_custom section="opinion" limit="8" form="opinion_list_form" />

The titles appear in the listing. I want the title to be a link to the article, but only if the article is NOT appearing on the current page. (Alternatively, I could not show an article in the sidebar, if it is being displayed on the current page.)

I’ve got code half working (shown below), but it only works on individual article pages. I’ve a number of other ways, but none worked.

Can you suggest a solution so links (or that editorial’s listing) only appear if the article is not the current page?

<code>

<txp:asy_wondertag> <txp:if_article_id id=”<txp:page_url type=“id” />”> <h4><txp:title /></h4> <txp:else /> <h4><txp:permlink><txp:title /></txp:permlink></h4> </txp:if_article_id>
</txp:asy_wondertag>

</code>

Last edited by azw (2007-03-07 13:23:44)

Offline

#2 2007-03-08 01:20:29

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: How to NOT show a link if the link is the same as the current page?

<txp:if_individual_article>
	<txp:asy_wondertag>
		<txp:if_article_id id="<txp:page_url type="id" />">
			<h4><txp:title /></h4>
		<txp:else />
			<h4><txp:permlink><txp:title /></txp:permlink></h4>  
		</txp:if_article_id>
	</txp:asy_wondertag>
<txp:else />
	<h4><txp:permlink><txp:title /></txp:permlink></h4>
</txp:if_individual_article>

Offline

#3 2007-03-08 06:43:18

azw
Member
Registered: 2007-01-29
Posts: 279

Re: How to NOT show a link if the link is the same as the current page?

Thanks for responding, Mary. I was hoping you’d take a look at the problem!

It sure looks like your code should work, but it doesn’t. Nothing ever prints out as a result, no matter what kind of page you’re on. I added <hr /> above and below your code just to be sure. It’s always empty. Odd, isn’t it?

I’ve gotten fairly close with this:

<txp:if_section name="opinion">
  <txp:glx_if_not_section_frontpage>
    <txp:asy_wondertag>
      <txp:if_article_id id="<txp:page_url type="id" />">

        -- the "if" conditional does not work --
        <h4><txp:title /></h4>

      <txp:else />

        -- the "else" does not work either --
        <h4><txp:permlink><txp:title /></txp:permlink></h4>

      </txp:if_article_id>
  <txp:else />

    -- this works --
    <h4><txp:permlink><txp:title /></txp:permlink></h4>

  </txp:glx_if_not_section_frontpage>
<txp:else />

  -- this works --
  <h4><txp:permlink><txp:title /></txp:permlink></h4>

</txp:if_section>

But it never prints anything that’s inside the <txp:if_article_id id="<txp:page_url type="id" />"> conditional (neither for the if nor for the else). I suppose that means that the <txp:if_article_id id="<txp:page_url type="id" />"> statement is not working.

Outside fo the conditionals, I have used:

<p>article_id: <txp:article_id /><br />
page id: <txp:page_url type="id" /><br />
page url: <txp:page_url /></p>

to display the values of the variables. Nothing prints even though the variables read:
article_id: 10
page id: 10
page url: /opinion/xyz1

or

article_id: 25
page id: 10
page url: /opinion/xyx2

Is there another way to do this without the asy_wondertags?

Offline

#4 2007-03-08 08:47:43

azw
Member
Registered: 2007-01-29
Posts: 279

Re: How to NOT show a link if the link is the same as the current page?

Please read the message right above this first. This is addition info on my testing.

The code below works partially, too.

<txp:asy_wondertag>
  <txp:if_article_id id="<txp:page_url type="id" />">
    <h4><txp:title /></h4>
  <txp:else />
    <h4><txp:permlink><txp:title /></txp:permlink></h4>  
  </txp:if_article_id>
</txp:asy_wondertag>

That works great on the article pages within the opinion section, but on the article_custom list page it doesn’t work, probably because there is the value for page_id is null (at least nothing appears when I ask it to print).

(It also works on any article page in other sections, but doesn’t work on their article_custom list pages, either.)

I think we could get this working if we didn’t have to use azy_wondertag. Maybe we should use PHP directly?

Last edited by azw (2007-03-08 08:49:16)

Offline

#5 2007-03-09 07:00:14

azw
Member
Registered: 2007-01-29
Posts: 279

Re: How to NOT show a link if the link is the same as the current page?

This php code seems to do the trick:

<txp:php>

  $azw_current_page_id = page_url (array(
    'type' => 'id'
    ));

  $azw_listed_article_id =article_id (array());

  $azw_title = title (array());
  $azw_permlink = permlink (array());

  if ( $azw_current_page_id == $azw_listed_article_id )
  {
    echo "<h4>" . $azw_title . "</h4>";
  }
  else
  {
      echo "<h4><a href='" . $azw_permlink . "' title='" . $azw_title . "'>" . $azw_title . "</a></h4>";
  }

</txp:php>

Using php was much simpler than fighting with the limited conditionals in txp.

I’d be interested in knowing if there is an easier way to use permlink within the echoed html or if there could be improvements in the code.

Last edited by azw (2007-03-09 07:03:12)

Offline

Board footer

Powered by FluxBB