Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2016-03-02 20:01:26

jameslomax
Member
From: UK
Registered: 2005-05-09
Posts: 448
Website

Re: "latest article" tag

OK starting to get somewhere. I didn’t look in the default page. Now I have I see this:

<!— show most recent image —>
<txp:article_custom limit=“1” section=“photos” form=“photo_single” sort=“rand()” />
<txp:hide>
<!— show a random image —>
<txp:article limit=“1” form=“photo_front” />
</txp:hide>

I forgot that 2 or 3 years ago I did have a ‘latest photo’ display then changed it to random.

Which changes the situation again if I understand correctly.

What I’d like is to retain the initial ‘random’ display, but then have the “Home / Latest” button take you to the latest photo. And I’m now thinking (intuitively not technically) that maybe it has to be one or the other?

Last edited by jameslomax (2016-03-02 20:03:34)

Offline

#14 2016-03-02 20:59:27

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

Re: "latest article" tag

That’s good. It looks like an old option to show probably a single image is hidden, but your <!-- comments --> are swapped.

If you remove the sort="rand()" part, you get exactly what I wrote in the post above and will see the most recent image.

If you’d like to keep the random image for the home page but also have latest, it’s probably easiest to do with two sections.

  • default section with the “home” button, and
  • “latest” section called up by clicking a “latest” (or “home”) button

To do that create a new section in the “Presentation > Sections” panel called “latest” and assign it the same page template as you have for the default section.

Replace the code you posted in the last post with:

<txp:if_section name="latest">
  <!-- on latest section: show most recent photo -->
  <txp:article_custom limit="1" section="photos" form="photo_single" />
<txp:else />
  <!-- otherwise show random image -->
  <txp:article_custom limit="1" section="photos" form="photo_single" sort="rand()" />
</txp:if_section>

Then you need to adapt your menu navigation. You could do something like this (borrowing from the code you posted further above):

<ul id="nav-list">
  <li<txp:if_section name="default,latest"> class="current"</txp:if_section>>
    <a href="/latest" title=""><txp:if_section name="default">Home<txp:else />Latest</txp:if_section></a></li>
…

Which means anyone typing in www.jameslomax.com will see the random image and a home button as before, except that clicking on “Home” takes you to the latest rather than to a random image. On the other sections, the button that was “Home” is now called “Latest”.

If you find that confusing and decide you would rather have “Home” and “Latest” menu buttons, then do:

<ul id="nav-list">
  <li<txp:if_section name="default"> class="current"</txp:if_section>>
    <a href="/" title="">Home</a>
  </li>
  <li<txp:if_section name="latest"> class="current"</txp:if_section>>
    <a href="/latest" title="">Latest</a>
  </li>
…

I think that should do it!


TXP Builders – finely-crafted code, design and txp

Offline

#15 2016-03-03 21:21:12

jameslomax
Member
From: UK
Registered: 2005-05-09
Posts: 448
Website

Re: "latest article" tag

Many thanks. I can do that.

Having now changed the behaviour to a standard ‘latest’ display I’m thinking I might leave it at that for now. The reason I changed it 2/3 years ago is I wasn’t posting much which meant a “dead” front page.

Now I see it in action – I realize actually, I’m posting more now so the ‘latest’ display makes sense. And there are good reasons, I think, to have the ‘latest’ appear first.

If that changes, which it might, I’ll use the above which seems straightforward (not much code understanding required, just working the parts of TXP).

Offline

#16 2016-03-05 13:32:15

jameslomax
Member
From: UK
Registered: 2005-05-09
Posts: 448
Website

Re: "latest article" tag

I’ll do the rest of that as an exercise so I can stay on top of understanding this and how it works. Thanks again. I will need the ‘random’ some time and will switch between the two.

Offline

Board footer

Powered by FluxBB