Help adding unique text to each page displayed

As mentioned in post" #30

<?php 
// ...

echo '<br> line ==>  ' .__LINE__; die;

Adding the above will halt script execution and render prior output.

Thanks for your reply.

I don’t know where to add your suggestion.

When I add it like so:

<?php

var_dump( $valueToDisplay ); // displays contents of $valueToDisplay, can also be objects, arrays, etc

echo '<br> line ==> ' .__LINE__; // displays script line

die; // halts browser execution and display progress up to that point

I see this:

NULL
line ==> 5

Try moving the script further down to immediately after $text is declared and change value $valueToDisplay to $text.

Afterwards experiment by moving the lines further down… until you pinpoint the problem.

Goodnight

Much thanks again for your guidance.

I tried this:

$text = 'default';
var_dump($text);

echo '<br> line ==> ' .__LINE__;

die;





$category_id = '';
$videos = array();
if ($page == 'trending') {
    $title  = $lang->trending;
    $db->where('privacy', 0);
    $videos = $db->where('time', time() - 172800, '>')->orderBy('views', 'DESC')->get(T_VIDEOS, $limit);
    $text = 'trending text here';
}

else if ($page == 'latest') {
    $title  = $lang->latest_videos;
    $db->where('privacy', 0);
    $videos = $db->orderBy('id', 'DESC')->get(T_VIDEOS, $limit);
    $text = 'latest text here';
}

else if ($page == 'top') {
    $title  = $lang->top_videos;
    $db->where('privacy', 0);
    $videos = $db->orderBy('views', 'DESC')->get(T_VIDEOS, $limit);
    $text = 'top text here';
}

else if ($page == 'category') {
    if (!empty($_GET['id'])) {
        if (in_array($_GET['id'], array_keys($categories))) {
            $pt->page_url_ = $pt->config->site_url.'/videos/'.$page.'/'.$_GET['id'];
            $category = PT_Secure($_GET['id']);
            $title    = $categories[$category];
            $category_id = "data-category='$category'";

            if (!empty($_GET['sub_id'])) {
                 $is_found = $db->where('type',PT_Secure($_GET['id']))->where('lang_key',PT_Secure($_GET['sub_id']))->getValue(T_LANGS,'COUNT(*)');
                if ($is_found > 0) {
                    $pt->page_url_ = $pt->config->site_url.'/videos/'.$page.'/'.$_GET['id'].'/'.$_GET['sub_id'];
                    $db->where('sub_category', PT_Secure($_GET['sub_id']));
                }
            }
            $db->where('privacy', 0);
            $category_old = str_replace('category__', '', $category);
            $videos   = $db->where('category_id = "' . $category . '" OR category_id = "' . $category_old . '"')->orderBy('id', 'DESC')->get(T_VIDEOS, $limit);
			$text = 'category text here';

        } else {
            header("Location: " . PT_Link('404'));
            exit();
        }
    }
}

and see this:

string(7) “default”
line ==> 37

I added:

var_dump($text);
echo '
line ==> ’ .LINE;
die;

after each if and else if block of code and saw a blank html page. And when I added it after:

else if ($page == 'category') {
    if (!empty($_GET['id'])) {
        if (in_array($_GET['id'], array_keys($categories))) {
            $pt->page_url_ = $pt->config->site_url.'/videos/'.$page.'/'.$_GET['id'];
            $category = PT_Secure($_GET['id']);
            $title    = $categories[$category];
            $category_id = "data-category='$category'";

            if (!empty($_GET['sub_id'])) {
                 $is_found = $db->where('type',PT_Secure($_GET['id']))->where('lang_key',PT_Secure($_GET['sub_id']))->getValue(T_LANGS,'COUNT(*)');
                if ($is_found > 0) {
                    $pt->page_url_ = $pt->config->site_url.'/videos/'.$page.'/'.$_GET['id'].'/'.$_GET['sub_id'];
                    $db->where('sub_category', PT_Secure($_GET['sub_id']));
                }
            }
            $db->where('privacy', 0);
            $category_old = str_replace('category__', '', $category);
            $videos   = $db->where('category_id = "' . $category . '" OR category_id = "' . $category_old . '"')->orderBy('id', 'DESC')->get(T_VIDEOS, $limit);
			$text = 'category text here';

        } else {
            header("Location: " . PT_Link('404'));
            exit();
        }
    }
}

var_dump($text);

echo '<br> line ==> ' .__LINE__;

die;

I see this:

string(18) “category text here”
line ==> 91

I look forward to your comments

[quote=“ChrisjChrisj, post:32, topic:320601”]
When I add ‘category text here’ (to the fourth one) and var_dump($valueToDisplay); at the top of the page after <?php

I see NULL at the top right of blank page quickly, [/quote]

Where does $valueToDisplay come from? I don’t see anywhere that you define that variable in your code, so why would you try to display it? @John_Betong uses that as an example, meaning that you’d put your variable name in that spot.

Any of the three categories, or one category, one trending, one top?

If that’s for any of three categories, then surely that is correct and is now doing what you want?

1 Like

Thanks for your reply.

I believe I defined it here:

$text = 'default'; 
var_dump($text); 
echo '<br> line ==> ' .__LINE__; 
die;

next to var_dump

the three categories, are ‘trending’, ‘top’, ‘latest’?

They all show “HELLO category test here”.
Ultimately I’d like
trending page to show the text ‘trending text here’
and
top page to show the text ‘top text here’
and
latest page to show ‘latest text here’

so, as far as I can see it’s not doing what I want, it’s showing the same text ‘category text here’ on all three pages.

I look forward to any additional replies/assistance

What is/are the values of $page that you are testing with here?

I am a little confused by some of the terminology. You say

but are they categories in the sense that $page == "category" and “trending”, “top” or “latest” is denoted by $_GET['id'], or are the values of $page set to each of the above? By using “category” to describe them, it’s getting confusing.

Thanks for your reply.
Sorry for any confusion.
there are just 3 categories.
category 1 is titled ‘latest’
category 2 is titled ‘trending’
category 3 is titled ‘top’

is that helpful?

I look forward to your comments/suggestions/remedy

No. What is the value of $page for your testing? Is it always “category”, or is it one of the other values?

always ‘category’

Well then it’s not surprising that it always sets the contents of $text to be as you define it within the code that deals with that situation. If it’s never set to “trending”, “top” or the other one, it will never give it that value.

Within the code block that deals with $page == "category", how do you decide whether you are seeing trending, latest or top videos?

Thanks again for your message.
As I didn’t write this script, I’m not sure of the answer to your question. There is a file named categories.html that holds this code:

<div class="col-md-12">
	<div class="row">
        <div class="content pt_shadow">
            <div class="home-page-categories">
                <div class="title">
                    <h4>
						<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-tag" color="#384047"><path d="M20.59 13.41l-7.17 7.17a2 2 0 0 1-2.83 0L2 12V2h10l8.59 8.59a2 2 0 0 1 0 2.82z"></path><line x1="7" y1="7" x2="7" y2="7"></line></svg>&nbsp;&nbsp;{{CATEGORY_ONE_NAME}} 
                        <span class="view_more_link">
                            <a  data-load="<?php echo (!empty($pt->subscriptions)) ? '?link1=subscriptions' : '?link1=videos&page=category&id={{CATEGORY_ONE_ID}}' ?>" href="<?php echo (!empty($pt->subscriptions)) ? "{{LINK subscriptions}}" : "{{LINK videos/category/{{CATEGORY_ONE_ID}}}}" ?>">
                                {{LANG explore_more}} <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-right"><polyline points="9 18 15 12 9 6"></polyline></svg>
                            </a>
                        </span>
                    </h4>
                </div>
                <div class="videos">
                    <div class="row pt_cat_vid_list">
                        <?php 
                            foreach ($pt->cat_videos as $key => $video) {
                                $video = PT_GetVideoByID($video, 0, 0, 0);
                                echo PT_LoadPage('home/list', array(
                                    'ID' => $video->id,
                                    'TITLE' => $video->title,
                                    'VIEWS' => $video->views,
                                    'VIEWS_NUM' => number_format($video->views),
                                    'USER_DATA' => $video->owner,
                                    'THUMBNAIL' => $video->thumbnail,
                                    'URL' => $video->url,
                                    'TIME' => $video->time_ago,
                                    'DURATION' => $video->duration,
                                    'VIDEO_ID' => $video->video_id_,
                                    'VIDEO_ID_' => PT_Slug($video->title, $video->video_id)
                                ));
                            }
                        ?>
                        <div class="clear"></div>
                    </div>
                </div>
            </div>
            <div class="clear"></div>
        </div>
    </div>
</div>

I look forward to any comments

The code you originally posted showed four separate possible values for $page - “top”, “trending”, “latest” and “category”. I presumed early on that for “trending” videos, that would be the value of $page and therefore you could create your unique text inside the specific if-condition that deals with that value, and the same for the other three values.

Now that you have revealed that $page is always set to “category” regardless of anything, I first have to ask what on earth the point of the first three sections of code are?

That aside, it seems that the value of $_GET['id'] is what decides the category. You create an array at the top of your code called $categories, which you use to check whether the category is valid, and to assign the title.

So my advice would be:

  1. Create a second array using the same syntax and a different name in the code, and have that array contain your unique text values for each category, in the same order as the category names.

  2. Duplicate the line that retrieves the category title and use it to retrieve the unique text into your $text variable.

You have enough sample code and discussion within this thread to achieve both of those without any further help, as they are both simply copying one brief section of code and altering it. Please, please, have a go at it before coming back to ask for “any further advice” or “links to examples”.

1 Like

Thanks for your reply.

I don’t see an array at the top of the code called $categories.
I appreciate your advice, and have given it a try, but don’t know how to create what you’ve described

Yes, you’re quite right, all this back and forth has confused me and I was looking at the array called $pages. There is an array called $categories, because you use it in this line of code:

$title    = $categories[$category];

but I cannot see where it is defined.

So I guess the question is, what value of $_GET['id'] denotes which category you are showing? Or does something else define whether you are looking at trending, top or latest?

Thanks for your reply.
there are just 3 categories.
category_id 1 is titled ‘latest’
category_id 2 is titled ‘trending’
category_id 3 is titled ‘top’

And do those IDs come in via $_GET['id'] or some other way?

If they do, create an array in the same way that the $pages array is created, and give it a different name that isn’t used anywhere else. Put each of the bits of unique text into the array. Remember that by default the first element of an array is 0 rather than 1, so if the values above are correct you’ll have to put something else in for the first element.

In the code later on where you create $text, all you need to do is access the correct element of the array using code similar to the line that accesses the $categories array.

I’m confused. So you have pages “latest”, “trending” and “top”, but also categories “latest”, “trending” and “top”?
Are these the same things, or are the separate? If they are separate, how do they differ and/or what is their relation (if any)?

This appears to work successfully on the html page:


		<?php
		$_GET["id"];
		if ($_GET["id"] == 1){
    		echo "This is the Page 1";
		}
		else if ($_GET["id"] == 2){
		echo "This is the Page 2";
		}
		else if ($_GET["id"] == 3){
		echo "This is the Page 3";
		}
        		?>

Much thanks for all of your replies/suggestions/guidance

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.