Topic: Get current page

Hi everybody!
I have one question to prevent a "dublicate title" (for google quality guidelines)
I have this code in my index.php in <head></head> tags:

<?PHP
function title_values($id, $use_category)
    {
                $path = './news/data';//CHANGE PATH TO THE CUTENEWS DATA DIRECTORY HERE
        if ($use_category)
        {
            $cat_lines = file($path.'/category.db.php');
            foreach ($cat_lines as $cat_line)
                {
                    $cat_array = explode('|', $cat_line);
                    $my_cats[$cat_array[0]] = $cat_array[1];
                }
        }

        $news_lines = file($path.'/news.txt');
        foreach ($news_lines as $news_line)
            {
                $news_array = explode("|", $news_line);
                if ($news_array[0] == $id)
                    {
                        $title = strip_tags($news_array[2]);
                        $description = strip_tags($news_array[3]);

                        if ($use_category and !empty($news_array[6]))
                            {
                                if (strstr($news_array[6], ','))
                                    {
                                        $cat_array = explode(',', $news_array[6]);
                                        foreach ($cat_array as $category)
                                            $category_arr[] = $my_cats[$category];
                                    }
                                else $category_arr = $my_cats[$news_array[6]];
                            }
                    }
            }
        return array ($title, $category_arr, $description);
    }

if (isset($_GET['id']))
    {
        $title_values = title_values($_GET['id'], true);//change true to false if the category doesn't need to be in the titlebar.
        $title = $title_values[0];
        $description = $title_values[2];
        if (is_array($title_values[1])) $cat = ' - '.implode(' - ', $title_values[1]);
        else $cat = ' - '.$title_values[1];
       $description= str_replace('"', '', $description);
        echo "<title>".$title."".$cat." My Site Title</title>\n";
        echo "<meta name=\"description\" content=\"".$description."\" />";
    }

else
    {
        echo "<title>My default title</title>\n";
        echo "<meta name=\"description\" content=\"My default description.\" />";
    }
?>

I need in this line:         echo "<title>".$title."".$cat." My Site Title</title>\n"; before My Site Title to show a current page number, this is possible ?
Like:
My Site Title Page: 2
I would be very grateful to people who can do the check and put the definition in the script.
Thanks!

Re: Get current page

Any help ?  https://cutephp.com/forum/style_emoticons/default/rolleyes.gif

3 (edited by 2012-03-08 11:28:50)

Re: Get current page

Hmm... Easiest way would most likely be to add this

if (isset($_GET($start_from))) {
$number = 'What number you use in your include';
$page_number = floor($_GET($start_from) / $number);}
else $page_number = 1;


after the frst line (<?PHP), and then use

echo "<title>My Site ".$title." Page: ".$page_number."</title>\n";


for My Site Title Page: 2 format

Ofc, I suck at this, so I could be wrong

4 (edited by 2012-03-08 18:26:58)

Re: Get current page

Hi,
I get error on line 37,  i mean:
if (isset($_GET($start_from))) {
PP:Fatal error: Can't use function return value in write context in /web/index.php on line 37

Re: Get current page

if (isset($_GET['start_from'])) {
$number = 'What number you use in your include';
$page_number = floor($_GET($start_from) / $number);}
else $page_number = 1;

Ifa you got a weird idea of how to use $_GET

6 (edited by 2012-03-09 02:14:48)

Re: Get current page

Fatal error: Function name must be a string in web/index.php on line 39
(with your code FUNimations)

line 39:

$page_number = floor($_GET($start_from) / $number);}


7 (edited by 2012-03-09 04:42:41)

Re: Get current page

if (isset($_GET['start_from'])) {
$number = 'What number you use in your include';
$page_number = floor($_GET['start_from'] / $number);}
else $page_number = 1;

https://cutephp.com/forum/style_emoticons/default/biggrin.gif (too long break from coding it seems)

and val4o0o0, be sure to replace that "What number you use in your include" with what $number you use in your news include https://cutephp.com/forum/style_emoticons/default/smile.gif

8 (edited by 2012-03-09 13:04:25)

Re: Get current page

Ok now its work, but i have some problem, look:
http://store.picbg.net/pubpic/A7/91/ee3568fe9c64a791.png
When i browse on page 1 in title show's page 0, on page 2 it show page 1 and etc...

And when i browse on page 3 in title for news it shows again page 0:
http://store.picbg.net/pubpic/2B/DF/fc2fe7c89cf52bdf.png
Maybe in news title cant rework, but I wish in this case to show only in pages, not in the title news

Can fix it ?

============
Ok i fix a page numbers:

if (isset($_GET['start_from'])) {
$number = '6';
$page_number = floor($_GET['start_from'] / $number + 1);}
else $page_number = 1;

My last question:
How to prevent shows a page number in title news?

9 (edited by 2012-03-09 19:02:42)

Re: Get current page

Well, don't replace this

echo "<title>".$title."".$cat." My Site Title</title>\n";


but only this

echo "<title>My default title</title>\n";


Perhaps replacing above with

if (isset($_GET['start_from'])) echo "<title>My Site Page: ".$page_number."</title>\n";
else echo "<title>My Site</title>\n";


would work best for you

and here's a bit improved code

if (isset($_GET['start_from']) && $_GET['start_from'] != '0') {
$number = '6';
$page_number = $_GET['start_from'] / $number + 1;}
else $page_number = 1;

Re: Get current page

I try, but it doesn't work.