Jump to content

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

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?

Share this post

Link to post
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


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.

Share this post

Link to post
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.

Share this post

Link to post
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?

Share this post

Link to post
Share on other sites

Yes, it's difficult to tell since we don't know where your first foreach ends in your code above and whether you are overwriting the variable $child since we also don't know if $out is in the loop or not.

Share this post

Link to post
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

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...