Jump to content

My videos page is incorrectly linking to the wrong video :(


OrganizedFellow
 Share

Recommended Posts

My videos page is only showing one page and not the others ? Link here -> http://biz265.inmotionhosting.com/~lovero8/videos/

Currently 4 videos are shown (as expeccted) and it is linking each accordingly. But each page only shows the first link to the first video, not each one like it's supposed to - UGH!
I mean, each of the 4 pages only shows the link, description, etc. of the first posted video,thats not right.

I cant figure out why.

<?php
    namespace ProcessWire;
    
    $settings = $pages->get("template=settings");
    $videos   = $pages->get("template=videos");
?>

<nav pw-append='content-body'>
    <?=ukDescriptionListPages(page()->children)?> 
    <?php
        echo "<p>{$videos->youtube_description}</p>";
        echo "<p>{$videos->youtube_link}</p>";
    ?>

    We would love if you shared this video. Please feel free to copy and share the link below:
    <p><input class="uk-input" type="text" value="<?php echo $videos->youtube_sharelink; ?>" id="myInput"></p>
    <p><button class="uk-button" onclick="myFunction()">Copy Link</button></p>

</nav>

<aside id='sidebar' pw-prepend>
	<?=ukNav(page()->rootParent, "depth=3")?>
</aside>

<script>
    function myFunction() {
        /* Get the text field */
        var copyText = document.getElementById("myInput");
        /* Select the text field */
        copyText.select();
        copyText.setSelectionRange(0, 99999); /*For mobile devices*/
        /* Copy the text inside the text field */
        document.execCommand("copy");
        /* Alert the copied text */
        alert("Copied the text: " + copyText.value);
    } 
</script>

 

Link to comment
Share on other sites

I don't understand most of what's going on there, but the problem is probably that your $videos variable will always be the same page:

$videos   = $pages->get("template=videos");

Since you're using $pages->get this will always match the first page of template "video" on your site, independent of the current page. I don't know your tree structure, is the video a field of the current page, or a sub-page? In those cases you probably meant to use $page->get or $page->find.

@Klenkes Beat me to it ^^ But you can normal selectors inside $pages->get, though the results may be unintuitive because it will always return the first page found.

Just as a sidenote, check out the new Clipboard API, it's pretty cool. I'm using it here and it works well?

Link to comment
Share on other sites

5 minutes ago, Klenkes said:

In short:
$pages->get is supposed to get 1 page only, and you can't use template as a selector.

Try something like:


$videos = $pages->get($page->id);

This way you get the video of the current viewed page.

YUP!

 

That was it, haahaa, I knew it was something simple. Thank you amigo.

Link to comment
Share on other sites

21 hours ago, Klenkes said:

$pages->get is supposed to get 1 page only, and you can't use template as a selector.

Not true, this it totally legit:

$settings = $pages->get("template=settings");

When the setting template is set to only allow 1 page of that type, it will return the settings page; Similarly for the search page, you can do

$search = $pages->get("template=search");

this can be safer than referencing by ID – in most cases the search page is 1000, BUT if a client mistakenly trashes the search page, and you create a new replacement search page, then the template selector ends up being safer.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...