Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-01-26 22:52:38

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

txp:author in txp:article_custom still respects author context

Not sure if this is a bug, or user error on my part. Probably the latter ;-)

I’m currently doing a blog sidebar for a multi-author blog page with filters for blog archives by year, blog articles by category and blog articles by author.

The main column shows the respective blog article list with excerpts and is context-sensitive using txp:article. Everything works fine and responds to the different page contexts.

The sidebar shows the filters using txp:article_custom, txp:category_list etc. and remains whatever the page context. Here too everything’s fine until I switch to an author context page, when the blog author filter lists only the current author, although I am using txp:article_custom.

FWIW, this is what I’m using:

<!-- get author list using if_different and store in a variable -->
<!-- smd_wrap trims off an excess comma -->

<txp:variable name="news_authors">
<txp:smd_wrap transform="trim|,">
  <txp:article_custom section='<txp:section />' limit="999" sort="AuthorID asc" break="" status="4">
    <txp:if_different><txp:author />,</txp:if_different>
  </txp:article_custom>
</txp:smd_wrap>
</txp:variable>

<!-- output blog author filters from comma-separated list in variable -->

<h2>Authors</h2>
<nav id="author_archive">
  <ul class="sidebar_nav">
    <!-- rah_repeat iterates over list -->
    <txp:rah_repeat value='<txp:variable name="news_authors" />' sort="regular asc">
      <li>
        <!-- smd_wrap formats a proper link -->
        <a href="<txp:site_url /><txp:section />/author/<txp:smd_wrap transform="case|lower,replace|| |+"><txp:rah_repeat_value /></txp:smd_wrap>">
          <txp:rah_repeat_value />
        </a>
      </li>
    </txp:rah_repeat>
  </ul>
</nav>

perhaps a bit involved … but it works except for in an author context.

My guess is that txp:author is responding to the page context and not the article(_custom) context.

If I sidestep <txp:author /> and replace it with this …

<txp:php>echo get_author_name($thisarticle['authorid']);</txp:php>

… it works correctly in all situations including in an article author context.

Would that make a case for a txp:article_author tag?


TXP Builders – finely-crafted code, design and txp

Offline

#2 2015-01-26 23:53:23

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

Re: txp:author in txp:article_custom still respects author context

jakob wrote #287762:

My guess is that txp:author is responding to the page context and not the article(_custom) context.

Exactly. If Txp sees an author at the URL-level, that trumps any “local” author when using the <txp:author> tag without context.

However, you can force article author context inside your article(_custom) with txp:if_article_author, which pretty much does what your PHP snippet does.

It seems a little superfluous/counter-intuitive to have to explicitly ask “Does this article have an author?” inside an article context (of course it does!) but that’s the only native way to break the contract between URL and <txp:author> tag. Must admit I’ve never actually tried it, but that should give you a crutch to lean on, with luck. EDIT: That’s all gibberish, ignore me.

Last edited by Bloke (2015-01-27 14:47:54)


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-01-27 13:51:44

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

Re: txp:author in txp:article_custom still respects author context

Stef, that sounds plausible, but I can’t get it to work. I tried:

<txp:if_article_author><txp:author /></txp:if_article_author>

… and …

<txp:if_article_author name='<txp:author />'><txp:author /></txp:if_article_author>

.. and for the hell of it as a kind “hey, look over here please” …

<txp:if_article_author></txp:if_article_author><txp:author />

… all to no avail :-(

Am I muddling something?


TXP Builders – finely-crafted code, design and txp

Offline

#4 2015-01-27 14:46:19

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

Re: txp:author in txp:article_custom still respects author context

jakob wrote #287805:

I can’t get it to work.

Rats, that makes two of us.

Having actually tried it, and reading the code with a fresh pair of eyes, I can see that the conditional doesn’t actually propagate the article author forward into the container, which is a shame. It just uses it to determine whether or not to take action and then leaves the author tag to its whims.

I think your initial prognosis about an article_author tag might be the best way forward. Trying to retrofit the existing author tag to handle both cases is going to be tough. Having said that, under 4.6.x the author tags have been extended a little, and appear to be cognisant of a new global $thisauthor. I thought that might mean it could respond to local authorship better but, sadly, it behaves identically to 4.5.x, which probably means it’s a bug. I’ll trawl the code and see if this can be addressed.

In the meantime, your single line of PHP is probably the simplest route, and I’m sorry for the bogus info.


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

#5 2015-01-27 16:15:48

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

Re: txp:author in txp:article_custom still respects author context

Thanks for confirming. Glad if it helps in some small way.


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB