
| View previous topic :: View next topic |
| Author |
Message |
Tenshi Platinum Sponsor


Joined: 12 Apr 2003 Posts: 1598 Location: Enschede, The Netherlands
|
Posted: Mon Feb 26, 2007 7:08 pm Post subject: Total Posts v2.0 |
|
|
Title: Total Posts v2.0
Creator: Bram "Tenshi" Nijmeijer
E-mail: bram@nijmeijer.org
Website: http://www.bramn.com
Addition, suggestions & fixes: djm, hansfn and everyone else on the Pivot Forums!
Creation date: June 1, 2005
Last update: February 26, 2007
Download: http://files.bramn.com/pivot/snippet_totalposts_20070226.zip
Demo: http://www.bramn.com/history.php (while it lasts, scroll to bottom)
Contents of zipped file:- snippet_totalposts.php
- snippet_totalposts_conf.php
- readme_totalposts.txt (this file)
Usage:- unzip this package in your extensions/snippets/ folder;
- edit the configuration file (snippet_totalposts_conf.php) to your likings (see the file for extra instructions);
- place a [[totalposts:X]] tag in any of your template files;
- select a configuration array using the 'X' parameter or leave it blank for just one configuration.
Description:
The Total Posts snippet is a fully customizable addition for your Pivot Powered website, able to give the visitor an
overview of the total number of posts and comments subdivided by category (if wanted). Total Posts caches its generated
output for a small amount of time to relieve the webserver when 'Rebuilding all files'.
Further features include:- Multiple configurations for use in multiple layouts;
- Ignore or hide specific categories (already ignores the ones set to 'hidden' in the Pivot administration);
- Fully customizable output;
- Sort alphabetically, by numbers of comments or posts or by category sorting set in pivot admin;
- Sort descending or ascending;
- Alternative output options or 'renaming' for the 'default' category of pivot;
- User defined template can be used in the category links.
The tag by default works as follows; the first line shows the total amount of comments and posts (between parentheses). If there are multiple categories, the total amount of posts and comments (between parentheses) are displayed by category with a link to that category. By default if you haven't renamed the 'default' category during your pivot install, it'll be renamed to 'on the weblog'.
For further customization instructions consult the configuration file included in the ZIP file. _________________ bramn - When just a first name is not enough! |
|
| Back to top |
|
 |
holas Respected Pivot Enthusiast


Joined: 28 Nov 2006 Posts: 171
|
Posted: Tue Feb 27, 2007 6:30 pm Post subject: Re: Total Posts v2.0 |
|
|
Great Snippet. Can you write the complete tag ([[totalposts:X]]) that you used in your demo page?. How did you maded your history.php page?. Thank you very much. _________________ www.palasdepadel.net
Last edited by holas on Wed Feb 28, 2007 7:35 am; edited 1 time in total |
|
| Back to top |
|
 |
hansfn Pivot Team


Joined: 15 May 2004 Posts: 5289 Location: Molde, Norway
|
Posted: Tue Feb 27, 2007 9:29 pm Post subject: Re: Total Posts v2.0 |
|
|
I found a bug: When displaying the cache, the correct code is
| Code: |
| return "<!--CACHE HIT-->" . file_get_contents($cacheFile); |
The old code pointed to an non-existing file.
In addition your example config should use double in stead single quotes so \t and \n is expanded. _________________ My Pivot bookmarks, snippets and scripts| Pivot Documentation Project: Template tags |
|
| Back to top |
|
 |
Tenshi Platinum Sponsor


Joined: 12 Apr 2003 Posts: 1598 Location: Enschede, The Netherlands
|
Posted: Thu Mar 01, 2007 7:10 pm Post subject: Re: Total Posts v2.0 |
|
|
| holas wrote: |
| Great Snippet. Can you write the complete tag ([[totalposts:X]]) that you used in your demo page?. How did you maded your history.php page?. Thank you very much. |
I just used [[totalposts:2]], what do you want to know exactly?
A tutorial and accompanying snippet on how I did my archives or history page can be found on my website here:
http://www.bramn.com/archive/2007/02/16/Tutorial_The_Archive_Cloud
Thanks for the heads-up hansfn, my loyal debugger
PHP codes are fixed and ZIP file is updated (no filename change though). _________________ bramn - When just a first name is not enough! |
|
| Back to top |
|
 |
holas Respected Pivot Enthusiast


Joined: 28 Nov 2006 Posts: 171
|
Posted: Fri Mar 02, 2007 5:09 am Post subject: Re: Total Posts v2.0 |
|
|
I'll like to know the format that you use in your history.php. I want to show year per year with months include. Similar that your history. Thank you very much. _________________ www.palasdepadel.net |
|
| Back to top |
|
 |
Tenshi Platinum Sponsor


Joined: 12 Apr 2003 Posts: 1598 Location: Enschede, The Netherlands
|
|
| Back to top |
|
 |
holas Respected Pivot Enthusiast


Joined: 28 Nov 2006 Posts: 171
|
Posted: Sat Mar 03, 2007 4:26 am Post subject: Re: Total Posts v2.0 |
|
|
What link?. Thank you. _________________ www.palasdepadel.net |
|
| Back to top |
|
 |
Tenshi Platinum Sponsor


Joined: 12 Apr 2003 Posts: 1598 Location: Enschede, The Netherlands
|
|
| Back to top |
|
 |
hansfn Pivot Team


Joined: 15 May 2004 Posts: 5289 Location: Molde, Norway
|
Posted: Fri Oct 19, 2007 6:15 pm Post subject: Re: Total Posts v2.0 |
|
|
My latest fix to the total posts snippet - fixing:
1) Do not stop Pivot completely just because the cache file can't be deleted.
2) Fix the alphabetic sorting.
| Code: |
--- snippet_totalposts.php.old 2007-08-31 13:37:16.000000000 +0200
+++ snippet_totalposts.php.new 2007-10-19 23:08:45.000000000 +0200
@@ -17,5 +17,5 @@
if(filectime($cacheFile) < (time() - (60))) {
if(!unlink($cacheFile)) {
- die('cannot delete!');
+ debug('cannot delete!');
}
} else {
@@ -58,9 +58,9 @@
// Descending or ...
if($config['order'] == 'DESC') {
- $array_lowercase = array_map('strtolower', $postsCount);
+ $postsCount_lowercase = array_map('strtolower', array_keys($postsCount));
array_multisort($postsCount_lowercase, SORT_DESC, SORT_STRING, $postsCount);
// Ascending!
} else {
- $array_lowercase = array_map('strtolower', $postsCount);
+ $postsCount_lowercase = array_map('strtolower', array_keys($postsCount));
array_multisort($postsCount_lowercase, SORT_ASC, SORT_STRING, $postsCount);
} |
PS! Please add the version number as comments also inside snippet_totalposts.php so we know what version we are using. _________________ My Pivot bookmarks, snippets and scripts| Pivot Documentation Project: Template tags |
|
| Back to top |
|
 |
hansfn Pivot Team


Joined: 15 May 2004 Posts: 5289 Location: Molde, Norway
|
Posted: Tue Mar 11, 2008 4:37 pm Post subject: Re: Total Posts v2.0 |
|
|
An update to patch above - now also making the generated category URLs mod_rewrite aware:
| Code: |
--- snippet_totalposts.php.orig 2008-03-11 21:32:03.000000000 +0100
+++ snippet_totalposts.php 2008-03-11 21:34:37.000000000 +0100
@@ -3,5 +3,5 @@
function snippet_totalposts($configNum=1) {
- global $Paths, $Current_weblog;
+ global $Cfg, $Paths, $Current_weblog;
include($Paths["extensions_path"]."snippets/snippet_totalposts_conf.php");
@@ -17,5 +17,5 @@
if(filectime($cacheFile) < (time() - (60))) {
if(!unlink($cacheFile)) {
- die('cannot delete!');
+ debug('cannot delete!');
}
} else {
@@ -58,10 +58,10 @@
// Descending or ...
if($config['order'] == 'DESC') {
- $array_lowercase = array_map('strtolower', $postsCount);
- array_multisort($postsCount_lowercase, SORT_DESC, SORT_STRING, $postsCount);
+ $postsCount_lowercase = array_map('strtolower', array_keys($postsCount));
+ array_multisort($postsCount_lowercase, SORT_DESC, SORT_STRING, $postsCount);
// Ascending!
} else {
- $array_lowercase = array_map('strtolower', $postsCount);
- array_multisort($postsCount_lowercase, SORT_ASC, SORT_STRING, $postsCount);
+ $postsCount_lowercase = array_map('strtolower', array_keys($postsCount));
+ array_multisort($postsCount_lowercase, SORT_ASC, SORT_STRING, $postsCount);
}
@@ -136,10 +136,15 @@
if ($config['template'] != "") {
- $output = str_replace('%catlink%', '<a>%cat%</a>', $output);
+ $output = str_replace('%catlink%', '<a>%cat%</a>', $output);
$output = str_replace('%template%',$config['template'], $output);
} else {
- $output = str_replace('%catlink%', '<a>%cat%</a>', $output);
+ $output = str_replace('%catlink%', '<a>%cat%</a>', $output);
}
-
+ if (isset($Cfg['mod_rewrite']) && $Cfg['mod_rewrite']) {
+ $output = str_replace('%catscript%', $Paths['log_url'] . 'category/', $output);
+ } else {
+ $output = str_replace('%catscript%', $Paths['pivot_url'] . 'archive.php?c=', $output);
+ }
+
$output = str_replace('%cat%', $k, $output);
$output = str_replace('%catid%', para_category($k), $output); |
Please consider making a new release (with a version number inside). _________________ My Pivot bookmarks, snippets and scripts| Pivot Documentation Project: Template tags |
|
| Back to top |
|
 |
Kay Pivot Groupie In Training


Joined: 22 Oct 2008 Posts: 4
|
Posted: Wed Oct 22, 2008 2:12 pm Post subject: Re: Total Posts v2.0 |
|
|
Thanks for writing this snippet. It's a real useful addition to my blog.
At first I had trouble getting the alphabetical sorting to work though. I changed the php file according to hansfn's suggestions and it works now. But I'd prefer to sort by pivot sorting order, which doesn't work yet. When I set
$config[X]['sorting'] = "p";
it won't sort as expected. It keeps the sorting order for the parameter last used before I change it to 'p', I think. Can anyone fix the code so pivot sorting works?
My blog is here, and my snippet_totalposts_conf.php reads:
| Code: |
<?php
/*
You can use the following %tags% in the layout generated by [[totalposts]]
%tnp% - Returns the total number of posts (in that category, in numbers)
%tnump% - Returns the total number of posts (in that category, in words)
%tnc% - Returns the total number of comments (in that category, in numbers)
%tnumc% - Returns the total number of comments (in that category, in words)
%cat% - Returns the category title
%catid% - Returns the category id (used in links)
%catlink% - Returns a link to the category
%home% - Returns the path to your weblog frontpage
%pivot_home% - Returns the path to your pivot installation
%template% - Returns the template to be used (configured in this %file)
\n - Insert an 'end of line'
\t - Insert a TAB
All variables below can be set to nothing, to disable its generated output.
Be sure to escape double quotes like this: \"
Extend the number of configurations by copy/pasting the current lines to new lines and increasing the number between the square brackets.
Example 1: Lists all categories (except for the category 'Test', sorted descending after the number of entries) with its number of posts and comments and precedes the list with the total number of posts comments.
Example 2: Only shows one line with the total number of posts and comments.
*/
// Layout:
// First line of the generated output:
// example: 'A total of <b>%tnp% (%tnc%)</b> posts have been made of which:\n<ul>'
$config[1]['beginline'] = "<p>A total of <b>%tnp% (%tnc%)</b> posts have been made of which:</p>\n<ul>\n";
$config[2]['beginline'] = "<p>%tnp% posts with %tnc% comments</p>";
$config[3]['beginline'] = "";
// Lines per category of the generated output:
// example: '<li><b>%tnp% (%tnc%)</b> normal posts on the %catlink%</li>'
$config[1]['midline'] = "\t<li><b>%tnp% (%tnc%)</b> normal posts in %catlink%</li>\n";
$config[2]['midline'] = "";
$config[3]['midline'] = "%catlink% (%tnp% Artikel)<br>\n";
// Last line of the generated output, used for instance to close HTML lists:
// example: '</ul>';
$config[1]['endline'] = "</ul>";
$config[2]['endline'] = "";
$config[3]['endline'] = "";
// If the category name is 'default' the following line will be used:
// example: '<li><b>%tnp% (%tnc%)</b> normal posts on the <a>weblog</a></li>'
$config[1]['altmidline'] = "\t<li><b>%tnp% (%tnc%)</b> normal posts on the <a>weblog</a></li>\n";
$config[2]['altmidline'] = "";
$config[3]['altmidline'] = "Ohne Kategorie (%tnp% Artikel)<br>\n";
// If you want to use a specific template file in your category links you can define it here:
// If you don't know what this means just leave it empty :-)
// example: 'archivepage_template.html'
$config[1]['template'] = "";
$config[2]['template'] = "";
$config[3]['template'] = "";
// Ignoring:
// Comma seperated CASE SENSITIVE list of EXACT category names that will be ignored.
// Categories set 'Hidden' in the Pivot admin will automatically be ignored.
$config[1]['ignore'] = "Test";
$config[2]['ignore'] = "";
$config[3]['ignore'] = "linkdump";
// Sorting:
// If lines per category are generated these variables define how they are sorted.
// 'a' for alphabetical sorting (by category name),
// 'p' for pivot sorting order,
// 'c' for sorting by number of comments.
// 'e' or nothing for sorting by number of entries.
$config[1]['sorting'] = "e";
$config[2]['sorting'] = "";
$config[3]['sorting'] = "p";
// 'DESC' for descending, 'ASC' or nothing for ascending.
$config[1]['order'] = "DESC";
$config[2]['order'] = "";
$config[3]['order'] = "";
?>
|
I use the third configuration in my blog templates.
Thanks in advance! |
|
| Back to top |
|
 |
hansfn Pivot Team


Joined: 15 May 2004 Posts: 5289 Location: Molde, Norway
|
|
| Back to top |
|
 |
Kay Pivot Groupie In Training


Joined: 22 Oct 2008 Posts: 4
|
Posted: Mon Oct 27, 2008 2:50 am Post subject: Re: Total Posts v2.0 |
|
|
| Works like a charm. Many thanks! |
|
| Back to top |
|
 |
| View previous topic :: View next topic |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|