Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-06-02 01:08:05

ashground
Member
From: Vancouver, Canada
Registered: 2005-01-07
Posts: 63
Website

Show articles from every section, with pagination?

I have my articles in several sections, but no matter what section, I’d like them to appear in the section “blog”. That was easy enough — with article_custom, you can specify what sections you’d like to grab articles from. But when you use article_custom, you lose pagination. Does anyone have a simple solution for this? Or do I have to hack my own pagination to get what I want?

Offline

#2 2010-06-02 06:16:15

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

Re: Show articles from every section, with pagination?

ashground wrote:

… with article_custom, you can specify what sections you’d like to grab articles from. But when you use article_custom, you lose pagination. Does anyone have a simple solution for this?

txp tips


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

Offline

#3 2010-06-03 22:55:01

ashground
Member
From: Vancouver, Canada
Registered: 2005-01-07
Posts: 63
Website

Re: Show articles from every section, with pagination?

Thanks, colak. I looked over the code and decided to roll my own — exactly the same, but not requiring any plugins. The results, if anyone’s interested:

<txp:php>
	// Initial setup
	global $variable;
	$variable["article-limit"] = 10; // Set to whatever you want
	$variable["article-count"] = 0;
	if(isset($_GET["page"])) { $variable["page"] = $_GET["page"]; }
	else { $variable["page"] = 1; }
	$variable["offset"] = ($variable["page"]-1)*$variable["article-limit"];
</txp:php>
<txp:article_custom section="whatever sections you'd like" limit="9999" status="4">
	<txp:php>
		// Count the articles
		global $variable;
		$variable["article-count"]++;
	</txp:php>
</txp:article_custom>
<txp:php>
	// Determine the page count
	global $variable;
	$variable["page-count"] = ceil($variable["article-count"] / $variable["article-limit"]);
</txp:php>
<txp:article_custom section="whatever sections you'd like" pgonly="0" status="4" limit='<txp:variable name="article-limit" />' offset='<txp:variable name="offset" />' />
<txp:php>
	// Output pagination
	global $variable;
	if(($variable["page"]+1) <= $variable["page-count"]) {
		echo "<div class=\"older\"><a href=\"?page=". ($variable["page"]+1) ."\">Older articles &raquo;</a></div>";
	}
	if($variable["page"]-1) {
		echo "<div class=\"newer\"><a href=\"?page=". ($variable["page"]-1) ."\">&laquo; Newer articles</a></div>";
	}
</txp:php>

Offline

#4 2011-07-11 16:59:56

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 687
Website Mastodon

Re: Show articles from every section, with pagination?

Thanx Aaron for the script above, really helped me out.


A hole turned upside down is a dome, when there’s also gravity.

Offline

#5 2011-07-11 21:37:05

merz1
Member
From: Hamburg
Registered: 2006-05-04
Posts: 994
Website

Re: Show articles from every section, with pagination?

Aaron, if it works OK and nobody sees big holes you should post it as a comment on the txptips page

Oops, I see you did that already, thanks :)

As a perfectionist you’ll post a link back to this thread so people can see if refinements were offered here :)


Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML

Offline

#6 2011-07-13 09:08:44

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 687
Website Mastodon

Re: Show articles from every section, with pagination?

Had to change the last part of Aarons code
1. to have the Newer articles link appear on last page (in txp 4.4.1), and
2. to prevent Older articles link to appear, when the total number of articles is smaller than the pagination limit.
Also added a div.pagination containing everything for styling reasons:

<txp:php>
	// Output pagination
	global $variable;
if ($variable["article-limit"] <= $variable["article-count"]) {
echo '<div id="pagination">';
if(($variable["page"]+1) <= $variable["page-count"]) {
		echo "<div class=\"older\"><a href=\"?page=". ($variable["page"]+1) ."\">Older articles &raquo;</a></div>";
	if($variable["page"]-1) {
		echo "<div class=\"newer\"><a href=\"?page=". ($variable["page"]-1) ."\">&laquo; Newer articles</a></div>";
	} 
}
if(($variable["page"]) == $variable["page-count"]) {
		echo "<div class=\"newer\"><a href=\"?page=". ($variable["page"]-1) ."\">&laquo; Newer articles</a></div>";
	} 
echo '</div>';
}
</txp:php>

A hole turned upside down is a dome, when there’s also gravity.

Offline

#7 2011-07-13 10:04:55

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 687
Website Mastodon

Re: Show articles from every section, with pagination?

Trying to adapt Aarons script to work on a number of sections, but only display articles of the current section (1, 2 or 3)

1. Enclosed the script in <txp:if_section name ="1,2,3"> ... script ... </txp:if_section>
2. Replaced article_custom section="1,2,3" ... with article searchall="0" ... to keep the scope.

Now i find that $variable["article-count"]++; always gives me a value of 1, which leads to the pagination not appearing, although the $variable["article-limit"] is valued correctly and the page shows the desired number of articles.
I tried using <txp:mdn_count section="<txp:section />" /> to check if i can get the article count otherwise. But i get a number of zeros resembling the count of articles in the particular section. Like this: 0 0 0 instead of 3.

What i am doing wrong?

EDIT: Note, that my real section names are not 1,2,3…

Last edited by jayrope (2011-07-13 10:05:32)


A hole turned upside down is a dome, when there’s also gravity.

Offline

#8 2011-07-13 10:33:31

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 687
Website Mastodon

Re: Show articles from every section, with pagination?

Answering my own question, here’s the script, based on Aaron’s, to show articles of just the currently active section, one script for many section. Enjoy.

<txp:if_section name='sect-1, sect-2, sect-3, sect-4, sect-5, sect-6, sect-7'>
<txp:php>
// Initial setup
global $variable;
$variable["article-limit"] = 10; // change as desired
$variable["article-count"] = 0;
if(isset($_GET["page"])) { $variable["page"] = $_GET["page"]; }
else { $variable["page"] = 1; }
$variable["offset"] = ($variable["page"]-1)*$variable["article-limit"];
</txp:php>
<txp:article limit="9999" status="4" searchall="0" pgonly="0">
<txp:php>
	// Determine article & page count
	global $variable;
	$variable["article-count"]++;
	$variable["page-count"] = ceil($variable["article-count"] / $variable["article-limit"]);
</txp:php>
</txp:article>
<txp:article pgonly="0" status="4" searchall="0" limit='<txp:variable name="article-limit" />' offset='<txp:variable name="offset" />'  form="some-form" />
<txp:php>
// Output pagination
	global $variable;
// fixed for article numbers smaller than the limit
if ($variable["article-limit"] <= $variable["article-count"]) {
if(($variable["page"]+1) <= $variable["page-count"]) {
		echo "<div class=\"older\"><a href=\"?page=". ($variable["page"]+1) ."\">&lt; Older</a></div>";
	if($variable["page"]-1) {
		echo "<div class=\"newer\"><a href=\"?page=". ($variable["page"]-1) ."\">Newer &gt;</a></div>";
	} 
}
// fix for last page
if(($variable["page"]) == $variable["page-count"]) {
		echo "<div class=\"newer\"><a href=\"?page=". ($variable["page"]-1) ."\">Newer  &gt;</a></div>";
	} 
}
</txp:php>
</txp:if_section>

Last edited by jayrope (2011-07-13 12:05:00)


A hole turned upside down is a dome, when there’s also gravity.

Offline

#9 2011-07-13 11:05:50

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,303

Re: Show articles from every section, with pagination?

No semicolon here?
$variable["article-limit"] = 10 // change as desired

I’m just asking, as long as code is human readable I can try to understand what it does and learn from it.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#10 2011-07-13 12:06:24

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 687
Website Mastodon

Re: Show articles from every section, with pagination?

Danke Uli, i corrected my code above.
Basically i had to adapt my own version, drawing the article-limit from a variable in a second form, before posting here.
Anymore errors?


A hole turned upside down is a dome, when there’s also gravity.

Offline

#11 2011-07-14 11:44:32

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,303

Re: Show articles from every section, with pagination?

jayrope wrote:

Anymore errors?

Oh, just did a diff with BBEdit, I can’t proof-read PHP. The server’s your best proof reader :)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#12 2011-07-16 12:19:45

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 619
Website

Re: Show articles from every section, with pagination?

If you want then you can just use – rss_suparchive

Offline

Board footer

Powered by FluxBB