Reputation: 28437
I have a Drupal 7 website. What I want is the following:
- if a user is on a page called 'fotos(-20xx)' or 'filmpjes(-20xx)' (in which the content between brackets is optional and the x's are numerals from 0-9) nothing happens
- if a user is on page OTHER than the above, a new rel
atriibute is added to $attributes
This is what I had in mind:
$fotos = array('/fotos', '/fotos-2004', '/fotos-2005', '/fotos-2006', '/fotos-2007', '/fotos-2008', '/fotos-2009', '/fotos-2010', '/fotos-2011', '/filmpjes', '/filmpjes-2007', '/filmpjes-2009', '/filmpjes-2010', '/filmpjes-2011');
$currentpage = $_SERVER['REQUEST_URI'];
foreach ($fotos as $foto) {if($foto != $currentpage) {$attributes['rel'] = 'shadowbox';}}
This has got two problems:
Does anyone have any idea how this can be written in a short-hand snippet? And, more importantly, does anyone see the error?
Upvotes: 1
Views: 369
Reputation: 9616
I think your requirement is to add a variable when uri is not present in array.
$base = array('/fotos','/filmpjes');
$baseFotos = '/fotos-';
$baseFilm = '/filmpjes-';
$i = '2004'; $j = date('Y');
while ($i <= $j) {
$fotos[] = $baseFotos.$i;
$film [] = $baseFilm.$i;
$i++;
}
$result = array_merge($base,$fotos,$film);
// check if base uri in array.
if (!in_array($_SERVER['REQUEST_URI'], $result)) {
$attributes['rel'] = 'shadowbox';
}
Upvotes: 1
Reputation: 238
I'm just thinking about this line
<?php $currentpage = $_SERVER['REQUEST_URI']; ?>
Maybe this can be change to this instead
<?php $currentpage = drupal_get_path_alias($_GET['q']); ?>
Upvotes: 0
Reputation: 76870
To solve the problem of the years you could create $fotos
dinamically like this
<?php
$fixed = '/fotos';
$time = strtotime('now');
$year_start = '2004';
$year_end = date('Y', $time);
$fotos = array($fixed);
for( ; $year_start <= $year_end; $year_start++){
$fotos[] = "$fixed-$year_start";
}
i don't understand what the other snippets of code should do, but you are overriding the same elements every time!In any case you are talking about $attribute
but wrote $attributes
Upvotes: 0