Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-01-26 12:21:19

RedFox
Member
From: Netherlands
Registered: 2005-03-25
Posts: 805
Website

Sorting sections(names) by name ... how?

I’m using this tagline to output articles from different sections:

<txp:article_custom section="nieuws,programmas,documenten,info" limit="22" wraptag="ul" class="small-block-grid-1 medium-block-grid-2 large-block-grid-4" break="li" form="article_excerpt" offset="" sort="" />

Is there a default input for sort="" to order sections the same as in section="nieuws,programmas,documenten,info" … !?

Or do I have to use a plugin like esq_sectionsort … !?

Last edited by RedFox (2015-01-26 12:22:13)

Offline

#2 2015-01-26 12:36:03

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,473

Re: Sorting sections(names) by name ... how?

See here.

Offline

#3 2015-01-26 15:36:01

RedFox
Member
From: Netherlands
Registered: 2005-03-25
Posts: 805
Website

Re: Sorting sections(names) by name ... how?

GugUser wrote #287730:

See here.

??

Offline

#4 2015-01-26 16:59:24

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

Re: Sorting sections(names) by name ... how?

So you want to sort by section but not alphabetically? It doesn’t look like that is easily done. sort accepts the a column name from the textpattern table or rand().


My Plugins

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

Offline

#5 2015-01-26 17:10:20

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

Re: Sorting sections(names) by name ... how?

You could do this:

<txp:section_list sections="nieuws,programmas,documenten,info" break="">
   <txp:article_custom section='<txp:section />' form="article_excerpt"
                       class="small-block-grid-1 medium-block-grid-2 large-block-grid-4" 
                       wraptag="ul" break="li"  
                       limit="22" offset="" sort="" />
</txp:section_list>

It calls article_custom once for each section, one after the other. If you (can) use page caching of that part of your page output, you can minimise the impact of the extra queries. You may need to adjust the limit attribute if you’re trying to get an exact number of matches. Alternatively run a counter in your form that adds one with each iteration and then cuts off after the number of items required.


TXP Builders – finely-crafted code, design and txp

Offline

#6 2015-01-26 18:28:46

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

Re: Sorting sections(names) by name ... how?

Hi Julian

That code would be very good for txptips. Would you mind submitting it there?


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

Offline

#7 2015-01-26 18:50:04

RedFox
Member
From: Netherlands
Registered: 2005-03-25
Posts: 805
Website

Re: Sorting sections(names) by name ... how?

This one does the job (too) … :)

<txp:article_custom section="nieuws,programmas,documenten,info" limit="22" wraptag="ul" class="small-block-grid-1 medium-block-grid-2 large-block-grid-4" break="li" form="article_excerpt" offset="" sort="Keywords asc" keywords="a,b,c,d" />

All articles (for the homepage) from section ‘Nieuws’ got a keyword ‘a’; all articles from section ‘Programma’s’ got the keyword ‘b’; and so on. The block-grid classes are from Foundation … so all articles from all sections follow each other in one grid. The tagline from @jacob does more or less the same, but the articles of each section get their own row … and that’s not desired.

Does this (under construction) look elegant or not … ;-)

Last edited by RedFox (2015-01-26 18:54:01)

Offline

#8 2015-01-26 20:23:03

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

Re: Sorting sections(names) by name ... how?

Interesting solution you adopted there. If I’ve understood you correctly, you don’t want the articles of a section to appear in a row but in a column beneath one another? Does that still work how you want it when the viewport gets smaller and you no longer have 4 columns? If I’ve understood your principle, it drops to two columns, then to one and the classes are interleaved so a, b, c, d at large viewports becomes a, b | c,d at medium viewports and a | b | c | d at small viewports.

You should be able to achieve a similar layout with a variation on the above suggested code, but with a different code order by wrapping the output from each section in a column div, then making those column class that float left, e.g.:

<div class="row">
   <txp:section_list sections="nieuws,programmas,documenten,info" break="">
   <div class="small-block-grid-1 medium-block-grid-2 large-block-grid-4">
      <txp:article_custom section='<txp:section />' form="article_excerpt"
                          class='article-<txp:section />'
                          wraptag="ul" break="li"  
                          limit="4" offset="" sort="" />
   </div>
   </txp:section_list>
</div>

The above should give you a grid of 16 articles, 4 columns, each with 4 articles, each with the articles from a particular section. At medium viewport, you get all the a×4, b×4 | c×4, d×4 and at small viewport a×4 | b×4 | c×4 | d×4. You might or might not like that arrangement at smaller viewports. The advantage with this approach is it avoids the need to enter extra layout cues in the keyword field.


TXP Builders – finely-crafted code, design and txp

Offline

#9 2015-01-27 08:15:25

RedFox
Member
From: Netherlands
Registered: 2005-03-25
Posts: 805
Website

Re: Sorting sections(names) by name ... how?

@jacob > the Foundation block-grid system does one thing … it fills up the horizontal width of the parent div with blocks (article’s) of equal width’s. On desktop 4 blocks, on tablets 2 and on smartphones 1. The number of article’s determines the height of that same div. In this case on desktop the disired order is:

a | a | a | b
b | c | c | d
d | d

And on tablet:

a | a
a | b
b | c
c | d
d | d

On smartphone:

a
a
a
b
b
c
… etc.

So, for now I’m a happy guy … :)

Last edited by RedFox (2015-01-27 08:20:04)

Offline

#10 2015-01-27 09:59:47

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Sorting sections(names) by name ... how?

Gave me the idea of a tiny plugin:

# Name: etc_sort v0.2 
# Type: Public plugin
# 
# Author: 
# URL: 
# Recommended load order: 5

# .....................................................................
# This is a plugin for Textpattern CMS - http://textpattern.com/
# To install: textpattern > admin > plugins
# Paste the following text into the 'Install plugin' box:
# .....................................................................

YToxMTp7czo0OiJuYW1lIjtzOjg6ImV0Y19zb3J0IjtzOjY6ImF1dGhvciI7czowOiIiO3M6
MTA6ImF1dGhvcl91cmkiO3M6MDoiIjtzOjc6InZlcnNpb24iO3M6MzoiMC4yIjtzOjExOiJk
ZXNjcmlwdGlvbiI7czowOiIiO3M6NDoiY29kZSI7czo2Mjc6Ii8vIFRYUCA0LjYgdGFnIHJl
Z2lzdHJhdGlvbg0KaWYgKGNsYXNzX2V4aXN0cygnXFRleHRwYXR0ZXJuXFRhZ1xSZWdpc3Ry
eScpKSB7DQoJVHhwOjpnZXQoJ1xUZXh0cGF0dGVyblxUYWdcUmVnaXN0cnknKS0+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mFsdWVzIGRpZmZlcmVudCBmcm9tIDxjb2RlPmFydGljbGVz
LCBibG9nLCBhYm91dDwvY29kZT4sIHdoaWNoIGlzIHRoZSBkZWZhdWx0IE15U1FMIGJlaGF2
aW9yLiBQYXNzIDxjb2RlPm5hdGl2ZT0mcXVvdDsxJnF1b3Q7PC9jb2RlPiBhdHRyaWJ1dGUg
dG8gPGNvZGU+ZXRjX3NvcnQ8L2NvZGU+IElmIHlvdSBwcmVmZXIgaXQuPC9wPiI7czozOiJt
ZDUiO3M6MzI6ImQ1ZmQ3ZTUwMGI1OWU4ODU0MjNmY2E3OThjMGRmZmU3Ijt9

You use it like this:

<txp:article_custom
	section="nieuws,programmas,documenten,info"
	sort='<txp:etc_sort field="Section" order="nieuws,programmas,documenten,info" />'
	limit="22" wraptag="ul" class="small-block-grid-1 medium-block-grid-2 large-block-grid-4" break="li" form="article_excerpt"
/>

Note that <txp:link_to_prev/next /> will probably not work as expected, but it’s a txp bug.

Offline

#11 2015-01-27 11:07:50

RedFox
Member
From: Netherlands
Registered: 2005-03-25
Posts: 805
Website

Re: Sorting sections(names) by name ... how?

<txp:article_custom section="nieuws,programmas,documenten,info" sort='<txp:etc_sort field="Section" order="nieuws,programmas,documenten,info" />' limit="24" wraptag="ul" class="small-block-grid-1 medium-block-grid-2 large-block-grid-4" break="li" form="article_excerpt" keywords="a,b,c,d" />

@etc > very nice

I presume there are no extra queries?

Now I (and my client) only has to use one keyword … ‘onHomepage’ or something like that … to sort out the needed articles. So keywords="a,b,c,d" will be keywords="onHomepage" … very convenient … :)

Offline

#12 2015-01-27 12:15:49

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Sorting sections(names) by name ... how?

RedFox wrote #287792:

I presume there are no extra queries?

Nothing I would worry about: an extra plugin table row and setting few MySQL variables. Both could be avoided, but our security department is untreatable.

Offline

Board footer

Powered by FluxBB