Recent Topics

1 Sep 29, 2007 23:18    

My b2evolution Version: 1.9.x

Hi,

I am using b2evo 1.9.2 and I´ve found some time ago a top artice hack somewhere here in the forum (can´t find the post anymore)... it works fine...

But... is it possible to create a simple top articles of the month hack? At the moment my top posting gets more and more hits... but perhaps the top articles of the month would be a great additional feature... is this possible?

Thanks in advance...
Daniel

2 Oct 05, 2007 08:20

Hmm, no solution for that?

4 Oct 05, 2007 10:30

Ah, no, not necessarily. Similar to my TOP 15 article-headlines displayed in the sidebar, I was looking for a possibility to not only show my most viewd postings of all time, but e.g. of the actual month (as well). So I (and all visitors) could see, what is/was of interest the most in the current month... and I would like to implement this in the sidebar... so for my understanding, no interaction with the sticky post plugin...

5 Oct 05, 2007 10:40

Can you provide me the code of the top 15 list?

6 Oct 05, 2007 10:44

Sure... especially because I couldn´t find it in the forum anymore... but I got the help from here... somewhere...

	<!-- =============== TOP ARTICLES =============== -->

	<?php
	echo "<div class=\"bSideItem\">
	      <h3 class=\"sideItemTitle\">Top 15 Artikel</h3>";
	      $TOPART = new ItemList($blog, array(), '', '', -1, '', array(),
	         '', 'DESC', 'views', 15);
	      echo "<ul>";
	      while ($TOPART_ITEM = $TOPART->get_item()) {
	         echo "<li><a href=\"", $TOPART_ITEM->permanent_url();
	         echo "\">", $TOPART_ITEM->title('','',false), "</a> <span class=\"notes\">(";
	         echo $TOPART_ITEM->views;
	         echo ")</span></li>";
	      }
	      echo "<li><a href=\"http://www.chaoszone.de/blog/index.php?orderby=views\">Mehr...</a></li></ul>";
	echo"</div>";
	?>

7 Oct 05, 2007 11:05

	<!-- =============== TOP ARTICLES OF THE MONTH =============== -->

	<?php
	echo "<div class=\"bSideItem\">
	      <h3 class=\"sideItemTitle\">Top 15 Artikel</h3>";
	      $TOPART = new ItemList($blog, array(), '', '', -1, '', array(),
	         '', 'DESC', 'views', 15, '', '', '', '', '', '', 0, '', mysql2timestamp(  date( 'Y-m-01 00:00:00', $servertimenow ) ) );
	      echo "<ul>";
	      while ($TOPART_ITEM = $TOPART->get_item()) {
	         echo "<li><a href=\"", $TOPART_ITEM->permanent_url();
	         echo "\">", $TOPART_ITEM->title('','',false), "</a> <span class=\"notes\">(";
	         echo $TOPART_ITEM->views;
	         echo ")</span></li>";
	      }
	      echo "<li><a href=\"http://www.chaoszone.de/blog/index.php?orderby=views\">Mehr...</a></li></ul>";
	echo"</div>";
	?>

¥
*edit* corrected date ;)

8 Oct 05, 2007 11:23

You want two new instances of this code, but with some minor differences. Most important: change the variable names to avoid conflicts.

Second you want to change this line:

$TOPART = new ItemList($blog, array(), '', '', -1, '', array(),
             '', 'DESC', 'views', 15); 


[url=http://doc.b2evolution.net/v-1-10/evocore/ItemList.html]Here[/url] is te technical doc's entry for this code.

The single most viewed article ever: change 15 om 1. That's easy.

The most viewed post of the current month:
1) add this code somewhere in the top of your snippet:

$today = getdate();
$this_month = $today[mon];

*edit*
This is the correct solution:

$today = getdate();
$this_month = $today['mon'];
$this_year = $today['year'];
$this_month = $this_year.$this_month;

2) change this line:

$TOPART = new ItemList($blog, array(), '', 
$this_month, -1, '', array(), '', 'DESC', 'views', 1);

¥åßßå beats me.

Good luck

9 Oct 05, 2007 13:14

Hey great... I wasn´t aware, that this is a content ;)

¥åßßå, I´ve integrated your code first, and in general it seems to work... There are x headlines displayed, only from this month etc. but before I get 3 times the same error message above the top list entries:

Notice: A non well formed numeric value encountered in /home/www/.../blog/inc/_misc/_misc.funcs.php on line 431

The _misc.funcs.php around the mentioned position says:

/**
 * Convert a MYSQL date to a UNIX timestamp
 */
function mysql2timestamp( $m )
{
	return mktime(substr($m,11,2),substr($m,14,2),substr($m,17,2),substr($m,5,2),substr($m,8,2),substr($m,0,4));
}

/**
 * Convert a MYSQL date -- WITHOUT the time -- to a UNIX timestamp
 */
function mysql2datestamp( $m )
{
	return mktime( 0, 0, 0, substr($m,5,2), substr($m,8,2), substr($m,0,4) );
}

/**
 * Format a MYSQL date to current locale date format.
 *
 * @param string MYSQL date YYYY-MM-DD HH:MM:SS
 */
function mysql2localedate( $mysqlstring )
{
	return mysql2date( locale_datefmt(), $mysqlstring );
}

function mysql2localetime( $mysqlstring )
{
	return mysql2date( locale_timefmt(), $mysqlstring );
}

function mysql2localedatetime( $mysqlstring )
{
	return mysql2date( locale_datefmt().' '.locale_timefmt(), $mysqlstring );
}

function mysql2localedatetime_spans( $mysqlstring )
{
	return '<span class="date">'
					.mysql2date( locale_datefmt(), $mysqlstring )
					.'</span> <span class="time">'
					.mysql2date( locale_timefmt(), $mysqlstring )
					.'</span>';
}

Afwas, after that I tried your version, and this was the result:

Notice: Use of undefined constant mon - assumed 'mon' in /home/www/.../blog/skins/custom/_main.php on line 7

Warning: Cannot modify header information - headers already sent by (output started at /home/www/.../blog/skins/custom/_main.php:7) in /home/www/.../blog/inc/MODEL/skins/_skin.funcs.php on line 71

Any ideas to make this happen without any error-messages?

10 Oct 05, 2007 13:19

Ah... found the solution, even when I´m not fully understanding this...

$TOPART = new ItemList($blog, array(), '', '', -1, '', array(), '', 'DESC', 'views', 5, '', '', '', '', '', '', 0, '', mysql2timestamp(  date( 'Y-m-01 00:00:01', $servertimenow ) ) );

So the working date format shall apparently be "Y-m-01 00:00:0[u]1[/u]"

11 Oct 05, 2007 14:55

Hi Daniel,

Sorry for the inconvenience, I didn't test the code (needed to run). From my solution this works (tested):

$today = getdate();
$this_month = $today['mon'];
$this_year = $today['year'];
$this_month = $this_year.$this_month;


replaces the snippet I mentioned.
This gives a number like 200710 and that triggers the correct month (october 2007).

¥åßßås code also works: he selects ALL posts and limits output to one month. He made a very funny mistake (bet he didn't check either) and you were a true Sherlock Holmes finding the solution.

Happy blogging

12 Oct 05, 2007 17:47

Afwas wrote:

he selects ALL posts and limits output to one month.

Close, it adds a where clause to the mysql to limit the selection of results to just a month ;)

Afwas wrote:

(bet he didn't check either)

Yer meant to test code? 8|

¥

13 Oct 05, 2007 21:19

LOL

(and thanks again for your help)

14 Oct 06, 2007 22:13

Thanks from me too, I didn't even know it was possible to sort by popularity (or show single article view counters). Now I'm a little depressed that my second most popular article has over 35000 views less than #1 :D

15 Oct 07, 2007 15:38

OFFTOPIC: 35000 views less? how much hits has your best article and what is your URL?

17 Oct 07, 2007 18:40

^^^thanks!

Daniel wrote:

OFFTOPIC: 35000 views less? how much hits has your best article and what is your URL?

www.yfinder.de

One of my posts got picked up by stumbleupon and garnered almost 40000 hits :)


Form is loading...