Textpattern CMS support forum

You are not logged in. Register | Login | Help

#151 2009-12-04 10:20:21

kostas45
Member
From: Greece
Registered: 2007-11-08
Posts: 61

Re: smd_query: Talk to the database directly via SQL

Stef, I am limiting to 5 and I get:

Page 1 of 4
Showing records 1 to 5 of 19

but Next 5 and Previous 5 do not print.

-Kostas

Offline

#152 2009-12-04 10:50:54

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,621
Website

Re: smd_query: Talk to the database directly via SQL

kostas45 wrote:

Page 1 of 4 Showing records 1 to 5 of 19 but Next 5 and Previous 5 do not print.

Weird, it works for me, though I have just thought of an enhancement: some new replacement variables to help with navigation that indicate how many records are on the next/prev pages and what the next/prev page numbers are. That will allow you to put the older/newer tags in your pageform and have it automaitcally render the correct number of records , e.g. Next 5, Next 5, Next 5, Next 4 in your case. It will also allow you to build your own next/prev links more easily. I’ll add that when I get a moment.

You may need to watch out for this caveat. It may be affecting you here(?)

Also, if you put the smd_query and associated older/newer tags inside an article they may not show up because, by their nature, they are designed to be used on list pages. I tried one a minute ago in an article and, although it rendered the next/prev links, their destinations were to the section landing page and not the article itself. My proposed fix above will address that so you can test for the existence of the next page and display your own next/prev links if you wish to do something a little more esoteric inside an article context.

After that I don’t know what could be up with your implementation. It works for me so it’ll probably be something subtle like the fact you only have a few articles or the newer/older tags are being intercepted by TXP’s article tag. It could be a bug in the plugin or a silly assumption I’ve made. Is there any more info you can supply, like where the smd_query tag is being used (page, form, section, article?), your exact tag code and a rough indication of how many articles are in the section in which the smd_query appears (because it may have a bearing on the results here).

Last edited by Bloke (2009-12-04 10:51:09)


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

#153 2009-12-04 19:01:42

kostas45
Member
From: Greece
Registered: 2007-11-08
Posts: 61

Re: smd_query: Talk to the database directly via SQL

Still no luck. It seems to me I need to change the whole site structure, for the older/newer tags to work!
I just need to page some records anywhere. I should not care if I am in the correct section, or in a list, or whatever. Just page records :-P
Hey, is this smd_pagicle territory? I believe, it is!
I think I ‘ll wait for it to grow up and be history aware ;-)
Stef, thanks anyway!

-Kostas

Offline

#154 2009-12-05 08:34:38

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,621
Website

Re: smd_query: Talk to the database directly via SQL

kostas45 wrote:

It seems to me I need to change the whole site structure, for the older/newer tags to work! I just need to page some records anywhere. I should not care if I am in the correct section, or in a list, or whatever.

If you’re using txp:older and txp:newer to page records, it does matter a great deal because those tags do specific things in TXP! I’ve allowed you to use them as a convenience to page records in this plugin. If you’re already using them for other things then you’ll have to build your own older/newer links because the plugin and your article list will clash.

The new version of the plugin (I altered it yesterday) allows you to more easily make your own links and separate the functionality of your smd_query from your article lists so you’re not tied to using the built-in older/newer tags. I’m just documenting it and then it’ll be released.


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

#155 2009-12-05 10:30:25

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,621
Website

Re: smd_query: Talk to the database directly via SQL

OK, try the enhanced v0.4

Features:

  • New replacement tags {smd_prevpage}, {smd_nextpage}, {smd_rows_prev} and {smd_rows_next} for greater flexibility in your pageform
  • New attribute: pagevar to control which variable smd_query uses for paging (in order to break the link between article paging and smd_query when using older/newer)
  • Two new conditional tags <txp:smd_query_if_prev> and <txp:smd_query_if_next>, useful for building your own pagination controls (you can of course use smd_if if you prefer)
  • Removed pgonly because paging can now only be done inside the pageform

See how you get on with that one. Remember, <txp:older> and <txp:newer> can now only step through smd_query results if they are used inside the pageform. smd_query no longer clobbers the ‘external’ paging information so it is is returned to its original state as soon as the smd_query closing tag is encountered.


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

#156 2009-12-05 11:31:40

kostas45
Member
From: Greece
Registered: 2007-11-08
Posts: 61

Re: smd_query: Talk to the database directly via SQL

My results from local testing of docs examples:

Example 10: It works, except:
I am using a sticky form to do fulltext searching, so I also need my url (get) vars on all pages together with the pg var.
Should next/prev links take account of that?

Example 11:
Same as above, url vars are not carried over to pages, plus:
Next/prev link targets are somehow wrong.

-Kostas

Offline

#157 2009-12-05 11:58:33

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,621
Website

Re: smd_query: Talk to the database directly via SQL

kostas45 wrote:

I also need my url (get) vars on all pages together with the pg var. Should next/prev links take account of that?

No. They can’t because txp:newer and txp:older don’t take them into account. smd_query doesn’t alter the tags’ functionality. They output a link to the current section’s list page and add ?pg=pagenum to the URL. Nothing more.

Example 11: Next/prev link targets are somehow wrong.

What do you mean “somehow wrong”? Look at the pageform in the example and see what it is doing, then alter it to suit your application. The example constructs links to the current article (using txp:permlink) so if you are using smd_query in an article it will page through the results and retain the current article in view. If you want to use it while in a list page you will need to change the anchor destinations accordingly.

Regarding the variables, the same applies. If you copied the example verbatim then it only adds the smd_qpg var to the links. If you want to tack on your existing URL params you will have to grab them from the URL and construct your links to include &param=val&some=var&.... You might like to consider adi_gps here, or use smd_query itself to grab (and optionally filter) the URL params then add them to your custom pagination links using the plugin’s ?varname notation to insert the variable names where you want them.


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

#158 2009-12-05 12:16:08

kostas45
Member
From: Greece
Registered: 2007-11-08
Posts: 61

Re: smd_query: Talk to the database directly via SQL

You are right! Sorry about that, I should have been more careful.
Custom pagination is definitely more useful :-)
Thanks for your help and work.

-Kostas

Offline

#159 2009-12-07 00:05:40

speeke
Member
From: Bruny Island, Australia
Registered: 2009-03-29
Posts: 161
Website

Re: smd_query: Talk to the database directly via SQL

Hi Stef,

I have begun looking at the new version, and am a little confused by all the extra gribble ;)

I am looking at a simple example to start with:

Existing article form

<txp:if_individual_article>
  <txp:smd_if field="prev_title, next_title" operator="isused, isused" logic="or">
    <h4>Adjacent Entries</h4>
    <ul>
      <txp:smd_if field="prev_title" operator="isused"><li><a href="<txp:link_to_prev />/">Previous Entry</a></li></txp:smd_if>
      <txp:smd_if field="next_title" operator="isused"><li><a href="<txp:link_to_next />/">Next Entry</a></li></txp:smd_if>
    </ul>
  </txp:smd_if>
</txp:if_individual_article>

New article form

<txp:if_individual_article>
  <txp:smd_if field="prev_title, next_title" operator="isused, isused" logic="or">
    <h4>Adjacent Entries</h4>
    <ul>
      <txp:smd_query_if_prev><li><a href="<txp:link_to_prev />/">Previous Entry</a></li></txp:smd_query_if_prev>
      <txp:smd_query_if_next><li><a href="<txp:link_to_next />/">Next Entry</a></li></txp:smd_query_if_next>
    </ul>
  </txp:smd_if>
</txp:if_individual_article>

However, when I use the new article form, I only see the Next Entry link which works OK except when I get to the last article in the section. It then shows a link to http://site.com/. The Previous Entry link never shows.

Also, can you please explain what pageform is? Is it a form of type article or misc ???

Last edited by speeke (2009-12-07 00:09:48)


“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower

Offline

#160 2009-12-07 09:39:04

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,621
Website

Re: smd_query: Talk to the database directly via SQL

speeke wrote:

I have begun looking at the new version, and am a little confused by all the extra gribble ;)

Having read through your code, I conclude it’s my crap documentation, sorry. I’ll see if I can tidy it up to make it clearer.

In the meantime, <txp:smd_query_if_prev> (and next) can only be used inside a pageform. Anywhere else they’ll do absolutely nothing (as you found!)

On a side note, <txp:link_to_prev> and <txp:link_to_next> shouldn’t need all the smd_if clutter, because they will automatically not render any container content if there is no next/prev article.

Also, can you please explain what pageform is? Is it a form of type article or misc ???

pageform is where you put a bunch of {} replacement tags (and/or navigation tags) to allow your visitors to page through your smd_query result sets. The replacement tags available are things that allow you to display stuff like “Showing records X to Y of Z” or “Previous M / Next N records”. And you can put TXP’s newer/older tags in here or construct your own, as shown in the plugin’s Example 11. You can place the contents of your pageform above or below the result set (or in both places!) using the pagepos attribute.

btw, it doesn’t matter what type you assign to your form. The types are just for your own organisational use and mean nothing above that.


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

Board footer

Powered by FluxBB