Syntax Problems of if Statement (php)

Posted by MxmastaMills on Stack Overflow See other posts from Stack Overflow or by MxmastaMills
Published on 2012-06-18T15:12:03Z Indexed on 2012/06/18 15:16 UTC
Read the original article Hit count: 154

Filed under:
|
|

I need a little help with an if statement in php. I'm trying to set a variable called offset according to a page that I am loading in WordPress. Here's the variable:

$offset = ($paged * 6);

What it does is it loads the first page, which is:

http://example.com/blog

and $offset is thus set to 0 because $paged is referring to the appending number on the URL. The second page, for example is:

http://example.com/blog/2/

which makes $offset set to 12. The problem is, I need the second page to define $offset as 6, the third page to define $offset as 12, etc. I tried using:

$offset = ($paged * 6 - 6)

which works except on the first page. On the first page it defines $offset as -6. SO, I wanted to create an if statement that says if $paged is equal to 0 then $offset is equal to 0, else $offset is equal to ($paged * 6 - 6).

I struggle with syntax, even though I understand what needs to be done here. Any help would be greatly appreciated. Thanks!

© Stack Overflow or respective owner

Related posts about php

Related posts about syntax