Textpattern CMS support forum

You are not logged in. Register | Login | Help

#31 2017-04-17 11:05:59

makss
Plugin Author
From: Ukraine
Registered: 2008-10-21
Posts: 355
Website

Re: aks_article : Extended article_custom tag

New version aks_article v0.3.1:

  • Txp 4.6 fix and Using SQL caching capabilities. Txp 4.6+
  • Added exclude attribute
  • Added aks_article_ids Txp variable – This is the ID of the articles that were displayed.
Show 3 random articles:
<txp:aks_article form="some_form" limit="3" sort="rand()" />
.
Show the rest of the article, excluding those already shown:
<txp:aks_article form="some_form" exclude='<txp:variable name="aks_article_ids"/>' />

Last edited by makss (2017-04-17 11:23:59)


aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)

Offline

#32 2017-04-17 11:58:07

whocarez
Plugin Author
From: Germany/Ukraine
Registered: 2007-10-08
Posts: 259
Website

Re: aks_article : Extended article_custom tag

thanks for this new version …

Got this error message in debug with now article shown after removing the ‘@’ before aks_article_doArticles :


Tag error: <txp:aks_article sort="custom_7 desc" wraptag="" break="" offset="1" limit="1" section="article" form="default_others_article" where="DATEDIFF(NOW(),Posted) <= 7" exclude="<txp:variable name='aks_article_ids' />" /> ->  Notice: Undefined offset: 1 while parsing form None on page default

textpattern/lib/txplib_misc.php(1782) : eval()'d code:39 aks_article_doArticles()
aks_article()
textpattern/vendors/Textpattern/Tag/Registry.php:83 call_user_func()
textpattern/lib/txplib_publish.php:514 Textpattern\Tag\Registry->process()
textpattern/lib/txplib_misc.php(1782) : eval()'d code:69 processTags()
adi_if_content()
textpattern/vendors/Textpattern/Tag/Registry.php:83 call_user_func()
textpattern/lib/txplib_publish.php:514 Textpattern\Tag\Registry->process()
textpattern/lib/txplib_publish.php:463 processTags()
textpattern/lib/txplib_misc.php(1782) : eval()'d code:83 parse()

The freshest article in this test environment is 11 days old.
In my form I build a top 3 of read articles with the help of aks_article, adi_if_content and dzd_counter_view. So aks_article should look first within the articles of the last week. If there is no article, than take the articles within the last month, if there is also no result take these within the last year. That’s the first run.
In the second run should aks_article look for the second most read article within the last week, month or year excluding the top 1 article from the first run. And in the end the third run, exclude the top 1 and top 2 articles. Maybe it is a little bit to complicated, but sometimes I do nothing on this website for more than a month, but I want to have a top 3 also in this time. But I cannot take the top 3 from the last year, because in this case the fresher ones are ignored, because of a lower read number.
Under some circumstances the the positions of some articles are the same, so one article can be doubled in this top 3, that’s why I want to exclude the earlier listed ones.
So, thats the “problem” in short.

Last edited by whocarez (2017-04-17 11:58:52)

Offline

#33 2017-04-17 12:04:31

makss
Plugin Author
From: Ukraine
Registered: 2008-10-21
Posts: 355
Website

Re: aks_article : Extended article_custom tag

exclude="<txp:variable name='aks_article_ids' />" – Embedded tag, single quotes are needed: exclude='<txp:variable name="aks_article_ids" />'


aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)

Offline

#34 2017-04-17 12:15:13

whocarez
Plugin Author
From: Germany/Ukraine
Registered: 2007-10-08
Posts: 259
Website

Re: aks_article : Extended article_custom tag

hm, I still get no output or better only output for the top 1 and the top 2

Tag error: <txp:aks_article sort="custom_7 desc" wraptag="article" break="" limit="1" section="article" form="default_first_article" where="DATEDIFF(NOW(),Posted) <= 7" /> ->  Notice: Undefined offset: 1 while parsing form None on page default

textpattern/lib/txplib_misc.php(1782) : eval()'d code:39 aks_article_doArticles()
aks_article()
textpattern/vendors/Textpattern/Tag/Registry.php:83 call_user_func()
textpattern/lib/txplib_publish.php:514 Textpattern\Tag\Registry->process()
textpattern/lib/txplib_misc.php(1782) : eval()'d code:69 processTags()
adi_if_content()
textpattern/vendors/Textpattern/Tag/Registry.php:83 call_user_func()
textpattern/lib/txplib_publish.php:514 Textpattern\Tag\Registry->process()
textpattern/lib/txplib_publish.php:463 processTags()
textpattern/lib/txplib_misc.php(1782) : eval()'d code:83 parse()

Tag error: <txp:aks_article sort="custom_7 desc" wraptag="" break="" offset="1" limit="1" section="article" form="default_others_article" where="DATEDIFF(NOW(),Posted) <= 7" exclude='<txp:variable name="aks_article_ids" />' /> ->  Notice: Undefined offset: 1 while parsing form None on page default

textpattern/lib/txplib_misc.php(1782) : eval()'d code:39 aks_article_doArticles()
aks_article()
textpattern/vendors/Textpattern/Tag/Registry.php:83 call_user_func()
textpattern/lib/txplib_publish.php:514 Textpattern\Tag\Registry->process()
textpattern/lib/txplib_misc.php(1782) : eval()'d code:69 processTags()
adi_if_content()
textpattern/vendors/Textpattern/Tag/Registry.php:83 call_user_func()
textpattern/lib/txplib_publish.php:514 Textpattern\Tag\Registry->process()
textpattern/lib/txplib_publish.php:463 processTags()
textpattern/lib/txplib_misc.php(1782) : eval()'d code:83 parse()

and in the source code of the rendered page I see this instead of the third article:
<txp:aks_article sort="custom_7 desc" wraptag="" break="" offset="2" limit="1" section="article" form="default_others_article" where="DATEDIFF(NOW(),Posted) <= 7" exclude='4609' />

Last edited by whocarez (2017-04-17 12:17:58)

Offline

#35 2017-04-17 17:32:30

makss
Plugin Author
From: Ukraine
Registered: 2008-10-21
Posts: 355
Website

Re: aks_article : Extended article_custom tag

whocarez wrote #305367:

In my form I build a top 3 of read articles with the help of aks_article, adi_if_content and dzd_counter_view. So aks_article should look first within the articles of the last week. If there is no article, than take the articles within the last month, if there is also no result take these within the last year. That’s the first run.
In the second run should aks_article look for the second most read article within the last week, month or year excluding the top 1 article from the first run. And in the end the third run, exclude the top 1 and top 2 articles. Maybe it is a little bit to complicated, but sometimes I do nothing on this website for more than a month, but I want to have a top 3 also in this time. But I cannot take the top 3 from the last year, because in this case the fresher ones are ignored, because of a lower read number.
Under some circumstances the the positions of some articles are the same, so one article can be doubled in this top 3, that’s why I want to exclude the earlier listed ones.
So, thats the “problem” in short.

Can solve this problem using the IF operator in MySQL.

  • The first Top range is last week: DATEDIFF(NOW(),Posted)<=7 – Let’s set this range to 0.
  • Second Top Month: DATEDIFF(NOW(),Posted)<=30 – Assign the value 1
  • Third Annual Top: DATEDIFF(NOW(),Posted)<=365 – value 2
  • All the rest, more than one year – value 3

Now we need to sort by the range number (the smaller the number, the more priority), and then by the number of views (custom_7 desc).

Outputs the Top 3 in one block:
<txp:aks_article sort="IF(DATEDIFF(NOW(),Posted)<=7, 0, IF(DATEDIFF(NOW(),Posted)<=30, 1, IF(DATEDIFF(NOW(),Posted)<=365, 2, 3))), custom_7 desc" wraptag="" break="" section="article" form="default_others_article" limit="3" />

If you want to display articles from the Top in different places of the template, then use the Txp variables:

Set variables:
<txp:aks_article sort="IF(DATEDIFF(NOW(),Posted)<=7, 0, IF(DATEDIFF(NOW(),Posted)<=30, 1, IF(DATEDIFF(NOW(),Posted)<=365, 2, 3))), custom_7 desc" section="article"  limit="3">
	<txp:variable name='top_result_<txp:aks_article_count />'>
		<txp:aks_article_count />: <txp:title />
	</txp:variable>
</txp:aks_article>
...
Show first: <txp:variable name="top_result_1" />
Second: <txp:variable name="top_result_2" />
The third result: <txp:variable name="top_result_3" />

aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)

Offline

#36 2017-04-18 11:51:28

whocarez
Plugin Author
From: Germany/Ukraine
Registered: 2007-10-08
Posts: 259
Website

Re: aks_article : Extended article_custom tag

Wow, impressive!! That simplifies the code considerably. Big thanks!

So for now I use it like that, because the first article uses another form for title, article_image etc.


<txp:aks_article sort="IF(DATEDIFF(NOW(),Posted)<=7, 0, IF(DATEDIFF(NOW(),Posted)<=30, 1, IF(DATEDIFF(NOW(),Posted)<=365, 2, 3))), custom_7 desc" section="article"  limit="3">
	<txp:variable name='top_result_<txp:aks_article_count />'>
		<txp:article_id />
	</txp:variable>
</txp:aks_article>

            <div class="general-art item-actual">
<!-- Nr.1 -->
                <txp:aks_article id='<txp:variable name="top_result_1" />' form="default_first_article" />
            </div>

            <div class="others-art item-actual">
<!-- Nr.2 -->
                <txp:aks_article id='<txp:variable name="top_result_2" />' form="default_others_article" />
<!-- Nr.3 -->
                <txp:aks_article id='<txp:variable name="top_result_3" />' form="default_others_article" />
            </div>

Offline

#37 2017-04-18 13:42:39

makss
Plugin Author
From: Ukraine
Registered: 2008-10-21
Posts: 355
Website

Re: aks_article : Extended article_custom tag

Can remove additional calls aks_article:

<txp:aks_article sort="IF(DATEDIFF(NOW(),Posted)<=7, 0, IF(DATEDIFF(NOW(),Posted)<=30, 1, IF(DATEDIFF(NOW(),Posted)<=365, 2, 3))), custom_7 desc" section="article"  limit="3">
	<txp:variable name='top_result_<txp:aks_article_count />'>
        <txp:if_variable name="aks_article_count" value="1">
            <txp:output_form form="default_first_article" />
        <txp:else />
            <txp:output_form form="default_others_article" />
        </txp:if_variable>
	</txp:variable>
</txp:aks_article>
            <div class="general-art item-actual">
<!-- Nr.1 -->
                <txp:variable name="top_result_1" />
            </div>
            <div class="others-art item-actual">
<!-- Nr.2 -->
                <txp:variable name="top_result_2" />
<!-- Nr.3 -->
                <txp:variable name="top_result_3" />
            </div>

aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)

Offline

#38 2017-04-18 14:12:31

whocarez
Plugin Author
From: Germany/Ukraine
Registered: 2007-10-08
Posts: 259
Website

Re: aks_article : Extended article_custom tag

thanks again …
somehow is <txp:if_variable name="aks_article_count" value="1"> not working, so I get instead every time default_others_article as form.

Offline

#39 2017-04-18 14:58:53

whocarez
Plugin Author
From: Germany/Ukraine
Registered: 2007-10-08
Posts: 259
Website

Re: aks_article : Extended article_custom tag

ok, if I define aks_article_count by myself, than it’s working …

<txp:variable name="aks_article_count" value='<txp:aks_article_count />' />

Offline

#40 2017-04-18 17:59:38

makss
Plugin Author
From: Ukraine
Registered: 2008-10-21
Posts: 355
Website

Re: aks_article : Extended article_custom tag

whocarez wrote #305379:

ok, if I define aks_article_count by myself, than it’s working …

<txp:variable name="aks_article_count" value='<txp:aks_article_count />' />

You’re right. This value was only available through the tag.

Fixed in the new version aks_article v0.3.2:

  • Now variable aks_article_count is available inside the form.

aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)

Offline

Board footer

Powered by FluxBB