Textpattern CMS support forum

You are not logged in. Register | Login | Help

#31 2014-01-05 04:44:32

monicahu
Member
From: Sydney NSW
Registered: 2009-03-07
Posts: 69

Re: [solved] Site problem after upgrade from 4.2 to 4.5.5

I’ve tried both methods from etc (Oleg) and colak (Yianni), but either getting tag errors or incorrect results (no article count and categories with nil articles being listed). I also tried the third method from TXP tips in an attempt to get the article count but having error when the count is zero.

The three methods are listed in below posts.

The results can be seen here

Last edited by monicahu (2014-01-05 04:55:28)


Monica
Life with God is the purpose.

Offline

#32 2014-01-05 04:48:55

monicahu
Member
From: Sydney NSW
Registered: 2009-03-07
Posts: 69

Re: [solved] Site problem after upgrade from 4.2 to 4.5.5

Method 1 – etc using plugin etc_query

code snippet

<txp:variable name="menu">
<ul id="menu">
  <txp:category_list section="blog" children="1" break="li">
    <txp:category title="1" />
    <txp:article_custom category='<txp:category />' section="blog" break="li" wraptag="ul" limit="999">
        <txp:permlink><txp:title /> :: <txp:author /> :: <txp:posted format="%d %b %Y" /></txp:permlink>
    </txp:article_custom>
  </txp:category_list>
</ul>
</txp:variable> 
<txp:etc_query data='<txp:variable name="menu" />'
	replace="ul/li[count(ul)=0];ul/li/ul^= ({count(li)})" />

Outcome: No output and there are tag errors in debugging mode.

Tag error: <txp:etc_query data='<txp:variable name="menu" />'
	replace="ul/li[count(ul)=0];ul/li/ul^= ({count(li)})" /> ->  Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given while parsing form None on page test
textpattern/lib/txplib_misc.php(812) : eval()'d code:578 DOMDocument->saveHTML()
textpattern/lib/txplib_misc.php(812) : eval()'d code:312 etc_evaluate_string()
textpattern/lib/txplib_publish.php:426 etc_query()
textpattern/lib/txplib_publish.php:326 processTags()
textpattern/publish/taghandlers.php:3789 parse()
textpattern/lib/txplib_publish.php:426 if_section()
textpattern/lib/txplib_publish.php:339 processTags()
textpattern/publish.php:544 parse()
index.php:83 textpattern()

PHP version 5.2.17 (seen from the diagnostics in my first post of this topic, page 1)

Last edited by monicahu (2014-01-05 05:03:40)


Monica
Life with God is the purpose.

Offline

#33 2014-01-05 04:53:11

monicahu
Member
From: Sydney NSW
Registered: 2009-03-07
Posts: 69

Re: [solved] Site problem after upgrade from 4.2 to 4.5.5

Method 2 – colak using native TXP tags

code snippet

<ul id="articles">
<txp:variable name="hasarticles" value='<txp:article_custom category=''<txp:category />'' status="live" section='blog' limit="1" />' />
<txp:if_variable name="hasarticles" value="">
<txp:else />
  <txp:category_list section='blog' break="li">
    <txp:category title="1" />
    <txp:article_custom category='<txp:category />' section='blog' break="li" wraptag="ul" limit="999">
        <txp:permlink><txp:title /> :: <txp:author /> :: <txp:posted format="%d %b %Y" /></txp:permlink>
    </txp:article_custom>
  </txp:category_list>
</txp:if_variable>
</ul>

Outcome: No article count (because there is no code to retrieve the count) and all categories are listed even when they don’t have articles in section called ‘blog’.

...
•	Anglicans
•	Apologetics
•	Bible Study
•	Children
       •	Of Ethics and Scripture :: Steven Layson :: 02 May 2010
       •	The Snow Queen :: Monica Hu :: 29 Oct 2009
       •	For Children - How to Pray :: Monica Hu :: 02 Sep 2009
...

Monica
Life with God is the purpose.

Offline

#34 2014-01-05 05:00:19

monicahu
Member
From: Sydney NSW
Registered: 2009-03-07
Posts: 69

Re: [solved] Site problem after upgrade from 4.2 to 4.5.5

Method 3 – adopted from TXP Tips using PHP codes and native TXP tags

code snippet

<txp:hide>PHP code for retrieving the article counts of the category</txp:hide>
<txp:php>
global $cat_totals;
$rs2 = safe_rows_start('Category1, count(*) as num', 'textpattern', "Section='blog' group by Category1");
while ($a = nextRow($rs2)) {
	$cat_totals[$a['Category1']] = $a['num'];
}
$rs2 = safe_rows_start('Category2, count(*) as num', 'textpattern', "Section='blog' group by Category2");
while ($a = nextRow($rs2)) {
	$name = $a['Category2'];
	$num = $a['num'];
	if (isset($cat_totals[$name]))	{
		$cat_totals[$name] += $num;
	} else {
		$cat_totals[$name] = $num;
	}
}
</txp:php>
<txp:category_list section='blog' wraptag="ul" break="" class="directory">
<li<txp:if_category name='<txp:category />'> class="active"</txp:if_category>>
<a href="<txp:site_url />test/?c=<txp:category />"><txp:category title="1" /> [<txp:php>global $cat_totals; echo $cat_totals[category(array())];</txp:php>]</a>
    <txp:article_custom category='<txp:category />' section='blog' break="li" wraptag="ul" limit="999">
        <txp:permlink><txp:title /> :: <txp:author /> :: <txp:posted format="%d %b %Y" /></txp:permlink>
    </txp:article_custom>
</li>
</txp:category_list>

The output contains errors when there is no article for a listed category. In fact, I don’t want that category to be listed. I don’t know how to modify the PHP code to do the error check.

…
•	Bible Study [
Tag error: <txp:php> ->  Notice: Undefined index:  bible_study while parsing form None on page test
textpattern/publish/taghandlers.php:3836 eval()
textpattern/lib/txplib_publish.php:426 php()
textpattern/lib/txplib_publish.php:339 processTags()
textpattern/publish/taghandlers.php:1209 parse()
textpattern/lib/txplib_publish.php:426 category_list()
textpattern/lib/txplib_publish.php:339 processTags()
textpattern/publish/taghandlers.php:3789 parse()
textpattern/lib/txplib_publish.php:426 if_section()
textpattern/lib/txplib_publish.php:339 processTags()
textpattern/publish.php:544 parse()
]
•	Children [3]
       •	Of Ethics and Scripture :: Steven Layson :: 02 May 2010
       •	The Snow Queen :: Monica Hu :: 29 Oct 2009
       •	For Children - How to Pray :: Monica Hu :: 02 Sep 2009

Monica
Life with God is the purpose.

Offline

#35 2014-01-05 07:28:45

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,289
Website

Re: [solved] Site problem after upgrade from 4.2 to 4.5.5

your code snippet in Method 2 is wrong. Try

<ul id="articles">
<txp:variable name="hasarticles" value='<txp:article_custom category=''<txp:category />'' status="live" section="blog" limit="1" />' />
<txp:if_variable name="hasarticles" value="">
<txp:else />
  <txp:category_list section="blog" break="li">
    <txp:category title="1" />
    <txp:article_custom category='<txp:category />' section="blog" break="li" wraptag="ul" limit="999">
        <txp:permlink><txp:title /> :: <txp:author /> :: <txp:posted format="%d %b %Y" /></txp:permlink>
    </txp:article_custom>
  </txp:category_list>
</txp:if_variable>
</ul>

Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | Respbublika! | NeMe @ github

Offline

#36 2014-01-05 07:47:57

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,289
Website

Re: [solved] Site problem after upgrade from 4.2 to 4.5.5

By the way… why did you change <txp:section /> to blog?


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | Respbublika! | NeMe @ github

Offline

#37 2014-01-05 08:07:37

monicahu
Member
From: Sydney NSW
Registered: 2009-03-07
Posts: 69

Re: [solved] Site problem after upgrade from 4.2 to 4.5.5

colak wrote #277792:

your code snippet in Method 2 is wrong. Try

<code>&lt;ul id="articles"&gt;...

Reason for limiting the section to ‘blog’ is that only articles from section blog are being counted and displayed. Other categories may have articles in other sections which I don’t want to include because they may be sermons, weblinks, events etc. and are not considered as real “articles” to the site visitors.

Have replaced the codes for Method 2 but results remain the same – categories without articles in section blog still appear.


Monica
Life with God is the purpose.

Offline

#38 2014-01-05 08:33:35

monicahu
Member
From: Sydney NSW
Registered: 2009-03-07
Posts: 69

Re: [solved] Site problem after upgrade from 4.2 to 4.5.5

Method 4 – using plugin mdn_count plus my own logic

code snippet

<txp:variable name="article_count" />
<txp:category_list section='blog' wraptag="ul" break="" class="directory">
  <txp:variable name="article_count"><txp:mdn_count section="blog" category='<txp:category />' /></txp:variable>
  <txp:if_variable name="article_count" value="0">
  <txp:else />
    <li<txp:if_category name='<txp:category />'> class="active"</txp:if_category>>
<a href="<txp:site_url />test/?c=<txp:category />"><txp:category title="1" /> [<txp:variable name="article_count" />]</a>
    <txp:article_custom category='<txp:category />' section='blog' break="li" wraptag="ul" limit="999">
      <txp:permlink><txp:title /> :: <txp:author /> :: <txp:posted format="%d %b %Y" /></txp:permlink>
    </txp:article_custom>
    </li>
  </txp:if_variable>
</txp:category_list>

The outcome is what I want to achieve. See results on this URL. Scroll to the bottom of the page to see the results.

Method 4 - using mdn_count
...
Children [3]
  Of Ethics and Scripture :: Steven Layson :: 02 May 2010
  The Snow Queen :: Monica Hu :: 29 Oct 2009
  For Children - How to Pray :: Monica Hu :: 02 Sep 2009
Christianity [3]
  The Christian and Poverty :: Steven Layson :: 13 Mar 2011
  Whatever the moments, think of God :: Monica Hu :: 02 Sep 2009
  Welcome to Thessalonica! :: Steven Layson :: 09 Aug 2009
Connect09 [4]
  Ideas for Connecting :: Steven Layson :: 23 Aug 2009
  Connect09 - Take the Hallway Challenge! :: St Peters :: 26 Jul 2009
  Uptight about evangelism :: Steven Layson :: 22 Feb 2009
  Preparing for Connect 09 :: Steven Layson :: 16 Oct 2008
...
  • However, I do wish to know how to get other methods work.
  • I also want a side menu on the same page just showing the categories with the count. When visitors click any category then only that category and the articles are shown in the main content area on the same page. See the original webpage here. You need to scroll down and pass the error messages.
  • Another way of not having the side menu will be using jquery to collapse and expand the categories, just like the FAQ on the textpattern.com. But then, I need to learn how to do this as I’m not a true blue software developer.

I setup the website myself in 2009. Our church is small and can’t afford to pay the professionals to do it. You guys have been very helpful. Very much appreciated your time.


Monica
Life with God is the purpose.

Offline

#39 2014-01-05 09:29:53

etc
Developer
Registered: 2010-11-11
Posts: 3,199
Website

Re: [solved] Site problem after upgrade from 4.2 to 4.5.5

monicahu wrote #277789:

PHP version 5.2.17 (seen from the diagnostics in my first post of this topic, page 1)

I have overlooked it, sorry, etc_query needs at least 5.3.8 to work. Any chance of upgrading? IMO, that would be the best option, since other methods require two db queries (count + retrieve) per category. You could also count articles with Javascript, but this is client-depending.

To hide articles in the side menu (with id="sidemenu", say), a quick and dirty way is CSS #sidemenu li ul{display:none} rule.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#40 2014-01-05 12:48:23

etc
Developer
Registered: 2010-11-11
Posts: 3,199
Website

Re: [solved] Site problem after upgrade from 4.2 to 4.5.5

Here is a js way to append counts and make article lists collapsible (no plugin needed, but will not work in 2% js-disabled browsers):

  • transform your snippet (mind linebreaks) into
<txp:category_list section='blog' wraptag="ul" break="" class="directory">
	<txp:variable name="article_list"><txp:article_custom category='<txp:category />' section='blog' break="li" wraptag="ul" limit="999">
			<txp:permlink><txp:title /> :: <txp:author /> :: <txp:posted format="%d %b %Y" /></txp:permlink>
		</txp:article_custom></txp:variable>
	<txp:if_variable name="article_list" value=""><txp:else />
		<li<txp:if_category name='<txp:category />'> class="active"</txp:if_category>>
			<a href="<txp:site_url />test/?c=<txp:category />"><txp:category title="1" /></a>
			<txp:variable name="article_list" />
		</li>
	</txp:if_variable>
</txp:category_list>
  • include (if not yet done) <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> in the <head> of your page form.
  • include the following script somewhere at the end of your page form:
<script>
$(function () {
	$("ul.directory>li>a").after(function(){
		var count = $(this).parent().children("ul").children("li").length;
		return (count ? "&nbsp;["+count+"]" :"");
	}).click(function(){
		$(this).parent().children("ul").toggle();return false;
	}).click();
});
</script>

etc_[ query | search | pagination | date | tree | cache ]

Offline

Board footer

Powered by FluxBB