Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

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

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: 11,448
Website GitHub

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

#161 2009-12-07 09:57:51

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

Re: smd_query: Talk to the database directly via SQL

Bloke wrote:

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.

Yes, that’s true. However, I don’t want an empty list if one or other are not true. Or an unnecessary <h4> title if neither are true. If there’s a cleaner way to do this, I’d love to know. I really like to get that XHTML validation tick, and make things as usable as possible ;-)

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.

That’s good to know. However, I thought some things had to go in an article type form for them to render???

Last edited by speeke (2009-12-07 12:18:24)


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

Offline

#162 2009-12-07 10:18:00

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

Re: smd_query: Talk to the database directly via SQL

speeke wrote:

I don’t want an empty list if one or other are not true

Can you do something like this? (untested)

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

That way if neither are present you see nothing, but if one or the other are present you enter the smd_if container whereby the link_to_prev/next containers will be displayed depending on which link(s) are available. And you will always get a valid XHTML list — even if it’s a list of one item.

EDIT: crap, no, you’re right. That’ll render the anchor around the <li>. You know what these two tags need? A wraptag attribute!

However, I thought some things had to go in an article type form for them to render

I don’t think so (someone correct me if I’m wrong). But if you want to preview the forms they have to be of type article.

Last edited by Bloke (2009-12-07 10:20:13)


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

#163 2009-12-07 12:13:46

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

Re: smd_query: Talk to the database directly via SQL

Bloke wrote:

You know what these two tags need? A wraptag attribute!

Indeed! But how to get one wraptag to work with two tags (<txp:smd_query_if_prev> and <txp:smd_query_if_next>). Now that presents a challenge! Could perhaps a break="li" be made available to these tags, assuming that <ul> is already hard-coded separately?

I don’t think so (someone correct me if I’m wrong). But if you want to preview the forms they have to be of type article.

I’m sure you’re right. I’ve read in Textpattern Solutions (p.193) the following, which I’ve just tested, but it appears not to hold true (perhaps Txp 4.2 has changed this by default?):

… As an example, although a misc-type form could not render a <txp:title /> tag … it could contain a <txp:article /> tag that referenced a proper article form containing the <txp:title /> tag.


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

Offline

#164 2009-12-07 22:49:34

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

Re: smd_query: Talk to the database directly via SQL

Also, is it possible to use <txp:smd_if /> in this context?

Page {smd_thispage} of {smd_pages} (Showing records {smd_row_start} to {smd_row_end} of {smd_allrows})
<txp:smd_if field="{smd_row_next}" operator="eq" value="1">
  ... variable "echeck" = Last entry
<txp:else />
  ... variable "echeck" = Next {smd_rows_next} entries
</txp:smd_if>

where

<a href="...{smd_nextpage}"><txp:variable name="echeck" /></a>

EDIT: Yes, it is. I misspelled smd_row_next above – should be smd_rows_next :-|

Last edited by speeke (2009-12-07 23:01:04)


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

Offline

#165 2010-01-11 00:27:55

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,

Happy New Year!

A (hopefully) quick query. I have the following:

<txp:smd_query query="SELECT ID FROM textpattern WHERE Section = '?s' AND Status = 4 AND (SUBSTR(Posted,1,10)='?month' OR SUBSTR(Posted,1,7)='?month' OR SUBSTR(Posted,1,4)='?month') GROUP BY Posted DESC" limit="1" pageform="content-main_nextprev">
    <txp:article listform="article_list" id="{ID}" />
<txp:else />
    No articles exist in this section for the date specified. Please try again.
</txp:smd_query>

All works well except when I add a date (in the url in the title bar) on which no articles were posted. If the user generates such a url, I would like to advise that “no articles exist”, hence the <txp:else /> tag, but the logic fails. I’ve tried various <txp:smd_if> configurations too, but to no avail.

Any suggestions greatly appreciated.

Last edited by speeke (2010-01-11 00:34:59)


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

Offline

#166 2010-01-11 09:39:11

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

Re: smd_query: Talk to the database directly via SQL

speeke wrote:

the logic fails

Hmmm, this is odd — and I know it isn’t much consolation — but your code seems to work for me. If I specify ?month=2008-06 where I know I have no articles, I see the ‘else’ message. Every other time I see an article and pagination links (incidentally, paging between articles is fun because the pagination form has to read the ?month and add it to the URL as well as the page variable!)

One thing you should probably alter is your txp:article; it should be <txp:article_custom /> because txp:article doesn’t take the id attribute since it’s context sensitive.

If that doesn’t help, I suggest adding debug="2" to the smd_query tag so we can see what the plugin sees on a page where there should be no articles. Let me know what you find, and I’ll help you dig further.

Happy New Year to you too. Hope it’s a good one.


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

#167 2010-01-11 11:20:22

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

Re: smd_query: Talk to the database directly via SQL

Bloke wrote:

One thing you should probably alter is your txp:article; it should be <txp:article_custom />

Yes, indeed. Although, strangely enough <txp:article /> worked perfectly well, or at least the same as <txp:article_custom />. And, no improvement with problem stated above.

If that doesn’t help, I suggest adding debug="2" to the smd_query tag

Done. When articles are found, the output appears as I imagine it should. However, there is no output at all for the <txp:else /> scenario. Could the fact that this code is in an article form be relevant? It is called from a page called “section” via:

<txp:article form="content-main_entries" limit="1" />

BTW: I’ve added the limit="1" to prevent those vicious end loops from repeating the articles ;)

Off to get some zzz’s now. Will check back on the morrow!


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

Offline

#168 2010-01-11 22:35:23

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

Re: smd_query: Talk to the database directly via SQL

Well, I think I’ve narrowed down when the problem’s occurring, but I have no idea why. The following code works perfectly in a page:

<txp:smd_switch item="?s">
  <txp:smd_case value="section-name">
  <txp:if_variable name="month" value="">
    month value is empty
  <txp:else />
    <txp:smd_query query="SELECT ID FROM textpattern WHERE Section = '?s' AND Status = 4 AND (SUBSTR(Posted,1,10)='?month' OR SUBSTR(Posted,1,7)='?month' OR SUBSTR(Posted,1,4)='?month') GROUP BY Posted DESC" limit="1">
      article list here
    <txp:else />
      error here
    </txp:smd_query>
  </txp:if_variable>
  </txp:smd_case>
</txp:smd_switch>

But as soon as I place this in an article form, and call it using the <txp:article /> in post #167 above, the error here message fails. All other logic works fine. I’ve tried exchanging ?s with ?section in the code, but no luck.

Stumps me! I’m hoping some Stef magic can enlighten me ;)

Last edited by speeke (2010-01-11 22:39:30)


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

Offline

Board footer

Powered by FluxBB