Recent Topics

1 Mar 27, 2006 09:29    

<?php if ($Item->views() >10) 
  {
      echo ' viewed '; 
      $Item->views(); 
      echo ' times ';
  }
?>

For some reason this is only showing 1 or -1

Who can write php in a correct way ?

2 Mar 27, 2006 16:22

That looks correct, so if it was me I'd do a teeny bit of troubleshooting. Oh and a teeny change or two to your code.

<?php
echo 'ITEM VIEWS IS '.$Item->views().'<br />';

if ( $Item->views() > 10 ) 
	{
		echo 'viewed ';
		$Item->views();
		echo ' times ';
	}
?>

That would tell me if I'm in the right neigborhood with my Item->views thing. Then just because I dunno why I'd think about this way instead.

<?php
echo 'ITEM VIEWS IS '.$Item->views().'<br />';

if ( $Item->views() >= 11 ) 
	{
		echo 'viewed ';
		$Item->views();
		echo ' times ';
	}
?>

To me guessing quickly is just like knowing what you're doing ;)

Hmmm.... I wonder if you need a ; after your views() thing?

3 Mar 27, 2006 16:27

By the way... $Item->get_views() should be more appropriate for a comparison, shouldn't it?

4 Mar 27, 2006 19:43

@madz : there is no get_views() in 1.6

<?php 
echo ' ITEM VIEWS IS '.$Item->views().' <br />'; 
if ( $Item->views() >= 11 ) 
   { 
      echo 'viewed '; 
      $Item->views(); 
      echo ' times '; 
   } 
   else
   {
      echo '<br /> viewed less then 10 times';
   }
?>

I only want to show how many times an articles has been viewed when it's an important article.
And for me an article is important when it's viewed al lot of times ;)

5 Mar 27, 2006 19:55

Totally off the top of my head (will check later if it deosn't work for you), use $Item->views instead of $Item->views()

¥

6 Mar 27, 2006 21:06

Yep just had a look at the code and $Item->views is the variable used by get_views() and views(), it is this one you should actually compare your treshold with.

@Topanga: get_views is in 1.6alpha released on main site (in evocore/_item.class.php, around line 1825)

7 Mar 27, 2006 21:42

YES !

and now I wanna know why $Item->views is logic ..
Is it something I can use on most functions ?

@madz : not that I want to argue after I found the solution, but in my 1.6 alpha there is no get_views....
It's the offical download from the site...

8 Mar 27, 2006 22:06

Sorry I didn't remember I was using the CVS (02-17-2006) version, just saw that CVS/ folder :D

9 Mar 28, 2006 01:11

Thanks ¥, though something is very wrong with someone who keeps code snippets on the top of their head.

<?php 
if ( $Item->views > 10 ) 
   { 
      echo 'viewed '; 
      $Item->views(); 
      echo ' times '; 
   } 
   else
   {
      echo 'viewed less then 10 times';
   }
?>

Tested in both 1.6 and my version of 1.7 and found to be quite groovy.

10 Mar 30, 2006 14:47

lol, no wonder people look at me weird :p

and now I wanna know why $Item->views is logic ..

Ok, it's a tad easier to explain this by using $Item->content & $Item->content();

$Item->content is a variable that holds the raw (unprocessed) post content. If you echo it to the screen you'll basically see what you typed in admin (ie/ no smilies rendered, all text before and after <!--more--> etc)

$Item->content() is a function that takes that raw data, throws it round all the relevant plugins, does some fancy stuff to work out what bit's meant to be seen ( before/after more, page ## of a multipage post etc) and then echo's it out to the screen.

Is it something I can use on most functions ?

Quite a few of the functions are named after the variable that they play with. If you look at the Item class (evocore/_item.class.php ) you can see all of the variables that you can access directly

¥

11 Mar 30, 2006 17:45

¥åßßå wrote:

Quite a few of the functions are named after the variable that they play with.

Well that makes sence to me..

Thank you very mutch for explaining..

The one has nothing to do with the other, it's only the programmers who made a 'logical' choice.


Form is loading...