Jump to content

Need help getting URL of a child page for use in it's parent.


MikeB
 Share

Recommended Posts

Once again I am stumped on something I feel I should know, and thought I did.

I won't bore you with the full code of my function but here are the relevant snipets.

function infoBoxesShow() {

  $infoBoxes = wire("pages")->find("parent=/info-articles/, template=infoItem");
  $infoCategories = wire("pages")->find("parent=/info-categories/, template=infoCategory");
  $out .="<div id='grida'>";

  foreach ($infoBoxes as $infoBox) {

    foreach($infoBox->infoCategory as $tag) {
      $tagname = $tag->name;
    }

    $child = $infoBox->child->url; /*Here is my issue, this is not getting picked up*/

Then further down the function the url should be output in a popup to get to the "Continue Reading ..." page.

    $out .="<div class='white-popup mfp-hide' id='{$infoBox->name}'>"; // PopUp Content

    $out .="<div class='media-box-title'>{$infoBox->headline}</div>"; // PopUp Title

    $out .="<div class='media-box-date'>{$infoBox->publish_date}</div>"; // PopUp Date

    $out .="<div class='media-box-text'>"; // PopUp Text

    $out .="<p>{$infoBox->summary}</p>"; // Some Content Here

    $out .="</div>"; // End of PopUp Text

    $out .="<div class='media-box-more'>"; // Read More

    $out .="<a href='{$child}'> {$infoBox->more_link_text} </a>"; // Link /*$child is not printing anything*/

    $out .="</div>"; //End of Read More

For the most part i think I have a reasonable understanding of Processwire API, until something like this throws me.

Any ideas what I am doing wrong?

Link to comment
Share on other sites

So, I am guess you have a pile of child pages under a parent and on the parent page you want to list and link to them?

If that is so, then you can get the children of a page with $page->children

http://cheatsheet.processwire.com/page/built-in-fields-reference/page-children/

So, you can loop through them with something like:

foreach($page->children as $child){

// add the specific div in here that has all you pop up stuff in it including:
echo "<a href='{$child->url}'>$child->title</a>";

}

obviously, vary to how your functionality works, but something like that.

Link to comment
Share on other sites

Almost what I am trying to do, but here is exactly as best I can describe.

I first find a bunch of pages($infoBoxes) with a certain parent and made of a certain template.

I then iterate over them assigning them as a variable($infoBox). 

Now I want to find the child page of that $infoBox and use it's url for a link to that page on it's parent.

Think like this, an image appears on my front page, there are a number of them. When you click them a pop-up appears with a summary of the article and a "Read More" link.

That link takes the user to the full article.

The full article is a child page of the summary in the processwire tree.

You can see this in action, or nearly, as the link is not working yet. But look here , scroll to the "info" section and checkout the first item, select it and you will see the pop-up with "Continue Reading".

Everything you see on the front page for each info article is in one processwire page for each, and the full article is a child of that page.

P.S. I thought as only one child I did not need the $pages array, so instead of children I was using child.

Link to comment
Share on other sites

P.S. I thought as only one child I did not need the $pages array, so instead of children I was using child.

Yes, that should be fine. Even if $infoBox had multiple children, this should work and give you the first child.

Perhaps the problem lies somewhere in the structure of your function. Would you mind posting the complete function? Is there anything else you do with the $child variable?

By the way, the links on your site seem to work right now?

Link to comment
Share on other sites

OK kill me for being an idiot.

To show my client the progress I am making I posted the dev site up to the server for him to see.

Now sometimes, I get confused as to which I am looking at for front end, and which i am developing. I need to do SCSS on local machine, and keep pinging back and forth.

So what happened is that down on local I changed the function to nice and simple as I described above. But on local I had forgotten to move the full articles under the summary. So that did not work.

Meanwhile up on the server I had moved them, but still had old code working out the link, which is what I was trying to tidy up.

Now have everything back in sync.

Note to self : Stop working on either local or dev, just use one, then sync at the end.


Thank you all for your patience and time. That was my bad. I need to tidy my development process.

  • Like 2
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...