Peter Knight

If URL or path contains

4 posts in this topic

<?php
if ($page->path == "/blog/posts/"){
echo "<script type='text/javascript' src='//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-55e5693b9add30c6'></script>";
}
?>

I'm trying to output a script on my blog posts only. They're all children of /blog/posts/ so I thought the above might work.

That seems to work only when the page loaded is exactly /blog/posts/

How can I tweak this to work on any page containing /blog/posts/ in it's URL / path and not just  /blog/posts/ ? 

I've been to the API and tried a few  variations using the following


if ($page->path *= "/blog/posts/")

but I think they're more selectors for fields?

Share this post


Link to post
Share on other sites

You can use strpos() function

<?php
if (strpos($page->path, "/blog/posts/") === 0){
	echo "...";
}
?>

 

Share this post


Link to post
Share on other sites
if($page->matches("has_parent=/blog/posts/")) {
}

 

Share this post


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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ngrmm
      i have a repeater with 2 fields
      – image
      – text
      if there are images uploaded then the output should be only the image field.
      if no images uploaded, then only the text-field should be shown
      right now, if the image-field is empty and the text-field is filled. i'm getting two boxes. and the first one is empty.
      <?php foreach($page->repeater as $box) { if($box->images) { ?> <div class="box images"> <?php foreach($box->images as $image) { echo "<img src='$image->url'/>"; } ?> </div> <?php } else { }   if($box->text) { ?> <div class="box text"><?php echo $box->text; ?></div> <?php } } ?>
    • By Deyan
      Hi,
      this is probably very easy to solve but I just can get the right output. This is the code:
      <?php //$tender_open is checkbox field; $tenders = $pages->find("template=tender, sort=-created, tender_open=$open"); ?> <h3>Tenders</h3> <?php if($open == 0) { echo '<p>There are no tenders available !</p>'; } else { ?> <ul class="no-style"> <?php foreach ($tenders as $t) { ?> <li> <a href="<?php echo $t->url; ?>"><?php echo $t->title; ?></a> <br> <p>Status: <span class="open">Open</span></p> </li> <?php } ?> </ul> <?php } ?> This is the snippet from the homepage. The code should check if there is an open tender available, if true = display it and if false just output echo "There are no tenders available". Tenders are on separate page tree with their own template.
      I must be doing something wrong here! Help.