Jump to content

Hide children of home from indexing (Single Page Site)


alexm
 Share

Recommended Posts

Hi guys,

New to the forums so I'm looking forward to having some great discussions.

First off, I'd obviously like to say what a great CMS/F, very neat and tidy and super simple to use. Nice one Ryan.

And secondly the community looks great.

Hopefully someone can help me with this... I see other similar topics on the forums but none that clear up this point.

I have a one page site.

I have used child pages of home as the different sections of the one page site. This populates MarkupSimpleNavigation with the menu system for the one page site as more sections are generated. That's perfect.

Now however lets say there is an about page. If I browse to domain.com/about/ I would like to hide the page and return 404. As this page is being pulled in by the home page. And shouldn't be accessible via url. Now the problem is I have templates assigned to each child page for obvious styling reasons so I can't create a page without a template file assigned.

How can I show hidden pages on the home page?

I have in my home.php template

foreach ($page->children() as $c) {
    echo $c->render(); // render the pages   
}

where I want to render each other page and template.

if I try to add

foreach ($page->children("include=hidden") as $c) {
    echo $c->render(); // render the pages   
}

I get redirected to domain.com/page/ with the following message: "The page you were looking for was not found" "Please use our search engine or navigation above to find the page"

Could anyone shed any light on how I might go about solving this? I don't mind having the pages hidden on the backend so this solution would be fine if it worked.

Thanks,

Alex

Link to comment
Share on other sites

Just for interest, if the menu is simply sending visitors to anchor text further down the home page (I assume that is how it is working), why would anyone know to go to /about/ in the first place?

If there is no link like that on the page, surely that URL wont be indexed by the search engines.

Link to comment
Share on other sites

alexmercenary,

How complex is the navigation? Do you even need a module?

Set the child pages to hidden, and then try this:

<ul>

<? foreach ($page->children("include=hidden") as $c): ?>
    <li><a href="#<?=$c->name;?>"><?=$c->title;?></a></li>

<? endforeach ?>

</ul>

P.S. Welcome to the forums. :)

  • Like 1
Link to comment
Share on other sites

@joss it's more a case of tidiness etc.

@renobird - thanks for the welcome. I don't think I made myself very clear. Sorry. The nav works fine. But Im using the separate pages on the backend as sections of a one page design. Now as these are pages I can still access them via their URL's.

As Joss points out this probably won't matter if there are no links to the page but I'm just wondering out of interest if there is a way of showing the hidden pages within my loop which grabs the different pages as sections of the one page design?

If not it's not a massive deal I guess, but more of a thought.

Thanks guys, sorry about the delayed reply, didn't get a notification of replies. I'm now following the topic so I guess I should.

Link to comment
Share on other sites

alexmercenary,

Coffee kicking in now. :)

I think you can pass an $options array to render (I know there is a post on this, but I can't find it).

foreach ($page->children("include=hidden") as $c) {
    echo $c->render(array('isInclude' => true)); // render the pages   
}

In the template file for your child pages:

if(isset($options['isInclude']) && $options['isInclude'] == true) {
    // code for your section
} else {
    $session->redirect("/");
}
Link to comment
Share on other sites

Hmm still as soon as I add include=hidden it just breaks the homepage and redirects to domain.com/page/ with the page not found message.

Perhaps I should just use an after hook to redirect. I dunno.

My heads not in it either right now. Coffee didn't help me, ha!

Link to comment
Share on other sites

I have a home.php file with basically the head and the footer and elements which are static. Then where I'm pulling in the pages with their templates assigned I'm literally using that code already posted

<?php
foreach ($page->children() as $p) {
    echo $p->render(); // render the pages   
}
?>

Then in each template there is just your usual eg.

<section class="arrow" id="<?php echo pageIdAttr($page->url); ?>">
    <div class="container inner">
        <div class="thin">
            <div class="section-title">
                <h2><?php echo $page->title; ?></h2>
            </div>
            <div class="row">
                
            </div>
            <!-- /.row -->
        </div>
    </div>
</section>
<?php echo renderTestimonial($pages->get(1002)->testimonial_repeater, 0, 'yellow', $config->urls->templates); ?>

Thanks

Link to comment
Share on other sites

That is weird. So if you just change the status to hidden it breaks? Even without adding hidden children to the $page->children pageArray?

Seems like something else is happening to cause that. I can't recreate it here.

Link to comment
Share on other sites

Hi alexmercenary,

I can confirm that the following works, and will indeed create a single page website where the child pages are included in the homepage, and are not accessible via URL. You don't need to set the child pages to hidden, the template logic takes care of the 404.

In my home.php template

<?php

include("./head.inc"); 

foreach ($pages->get('/')->children() as $p) {
    echo $p->render('children.php', array('isPartial' => true)); 
}

include("./foot.inc"); 

In my children.php template (assigned to all children of the home page)

<?php

if (isset($options['isPartial']) && $options['isPartial'] == true): ?>
    
    <section class="arrow" id="<?=$page->name; ?>">
        <h2><?=$page->title; ?></h2>
    </section>

<? else: ?>
    
    <?php throw new Wire404Exception(); ?>

<? endif; ?>
  • Like 4
Link to comment
Share on other sites

Should work as Reno is doing, but even before we could pass parameters to render() this would be possible by comparing the url with the page being rendered. In your case:

if ($page->url == $_SERVER["REQUEST_URI"]) throw new Wire404Exception();
  • Like 2
Link to comment
Share on other sites

renobird, diogo... Thank you both so much for your help!

diogos method works a charm as I'm sure would yours renobird, like you say it's just a bit cleaner for the purpose of what I want to achieve.

You are both legends.

What a lovely forum full of caring people!!

Thanks again

  • Like 2
Link to comment
Share on other sites

Sorry to dive in late.

Diogo's code would be equalent to:

if($page->url == $page->url) throw ....

Just looks cooler, but however I would simply not create the php template for those pages and create a separate template file.

If your template would be "subpage", create a  partial-subpage.php

And render the subpages on home with

echo $subpage->render("partial-subpage.php");

And since you don't have a subpage.php those won't be viewable anyway.

Redirect:

What you also could do is have the subpage.php redirect to the home with a hash /#yoo appended, so you could scroll to the panel and also use that url for indexing.

$session->redirect("/#" . $page->name);
  • Like 6
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...