PHP - PHP script para links no me funciona

 
Vista:
sin imagen de perfil
Val: 107
Ha disminuido 1 puesto en PHP (en relación al último mes)
Gráfica de PHP

PHP script para links no me funciona

Publicado por Joseba (56 intervenciones) el 10/12/2018 11:04:12
Aupa , me idea es hacer lo que hago con javascript https://www.lawebdelprogramador.com/foros/JavaScript/1677563-Javascript-Code-no-me-funciona.html#last , hacerlo con un php Script . Yo quiero que los links cambie de color , cuando este en esa pagina ... .

Yo creo que el problema esta en el Script php ,

1
2
3
4
5
6
7
8
<nav class="link_wechsel">
      <h2 class="visually-hidden">Page navigation</h2>
      <ul>
        <li><a <?php if ($current_page=="1"): ?>aria-current="page" <?php endif;?> href="beispiel-1.php">1</a></li>
        <li><a <?php if ($current_page=="2"): ?>aria-current="page" <?php endif ?> href="beispiel-2.php">2</a></li>
        <li><a <?php if ($current_page=="3"): ?>aria-current="page" <?php endif ?> href="beispiel-3.php">3</a></li>
      </ul>
</nav>


el archivo se llama header-beispiel.php , todo el code , que tengo en este archivo..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
 
header("Content-Type: text/html; Charset=utf-8");
mb_internal_encoding('UTF-8');
date_default_timezone_set('UTC');
error_reporting(E_ALL);
 
?>
 
<!doctype html>
 
<html lang="en">
 
<head>
 
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
 
<title>header-beispiel</title>
 
</head>
<style>
 
.link_wechsel ul {
 
    list-style-type: none;
 
    margin-left: 340px;
 
}
 
 
 
.link_wechsel li {
 
  display: inline;
 
}
 
 
 
.link_wechsel a {
 
   display: inline;
 
   text-decoration: none;
 
   border: 1px solid gray;
 
   background-color: #FE2E64;
 
   color: black;
 
   padding: 8px;
 
   opacity: 0.5;
 
   font-family: Times New Roman;
 
}
 
 
 
.link_wechsel a:hover {
 
   background-color: #9f9e9e;
 
}
 
 
.link_wechsel a.[aria-current=page] {
 
 
  background-color:green;
 
}
 
 
.mela a.[aria-current=page] {
 
 
  background-color:green;
 
}
 
 
 
 
</style>
 
<body>
 
<nav class="link_wechsel">
      <h2 class="visually-hidden">Page navigation</h2>
      <ul>
        <li><a <?php if ($current_page=="1"): ?>aria-current="page" <?php endif;?> href="beispiel-1.php">1</a></li>
        <li><a <?php if ($current_page=="2"): ?>aria-current="page" <?php endif ?> href="beispiel-2.php">2</a></li>
        <li><a <?php if ($current_page=="3"): ?>aria-current="page" <?php endif ?> href="beispiel-3.php">3</a></li>
      </ul>
</nav>
 
</body>
</html>



Luego tengo 3 archivos en php , se llaman beispiel-1.php , beispiel-2.php y beispiel-3.php , que tienen el mismo Code ,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
$current_page = "1";
require 'header-beispiel.php';
 
 
header("Content-Type: text/html; Charset=utf-8");
mb_internal_encoding('UTF-8');
date_default_timezone_set('UTC');
error_reporting(E_ALL);
 
?>
 
<!doctype html>
<html lang="en">
 
<head>
 
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
 
<title>beispiel-1</title>
 
</head>
 
<style>
 
 
 
</style>
 
<body>
 
<h3>Page 1</h3>
 
 
 
 
</body>
</html<

lo unico que cambia en cada uno es en $current_page = "1"; ,que seria $current_page = "1"; , $current_page = "2"; , $current_page = "3"; .

Me podria ayudar algien ha solucionar este problema , gracias !
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
1
Responder
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

PHP script para links no me funciona

Publicado por xve (6935 intervenciones) el 10/12/2018 17:31:53
Hola Joseba, en PHP yo haria algo así:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>header-beispiel</title>
</head>
<style>
 
.link_wechsel ul {
    list-style-type: none;
    margin-left: 340px;
}
 
.link_wechsel li {
  display: inline;
}
 
.link_wechsel a {
   display: inline;
   text-decoration: none;
   border: 1px solid gray;
   background-color: #FE2E64;
   color: black;
   padding: 8px;
   opacity: 0.5;
   font-family: Times New Roman;
}
 
.link_wechsel a:hover {
   background-color: #9f9e9e;
}
 
.link_wechsel a.[aria-current=page] {
    background-color:green;
}
 
.mela a.[aria-current=page] {
  background-color:green;
}
 
</style>
 
<body>
 
    <nav class="link_wechsel">
      <h2 class="visually-hidden">Page navigation</h2>
      <ul>
          <?php
          for($i=1;$i<=3;$i++)
          {
              if(basename($_SERVER["PHP_SELF"])=="beispiel-".$i.".php")
                  echo "<li><a aria-current='page' href='beispiel-".$i.".php'>".$i."</a></li>";
              else
                  echo "<li><a href='beispiel-".$i.".php'>".$i."</a></li>";
           }
           ?>
      </ul>
    </nav>
 
</body>
</html>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 107
Ha disminuido 1 puesto en PHP (en relación al último mes)
Gráfica de PHP

PHP script para links no me funciona

Publicado por Joseba (56 intervenciones) el 11/12/2018 19:49:15
Aupa , he provado con tu Code , pero no cambia el color... , he visto que tu Code no tiene ninguna Variable , entoces que tendria que poner en los archivos beispiel-1.php , beispiel-2.php y beispiel-3.php ?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 107
Ha disminuido 1 puesto en PHP (en relación al último mes)
Gráfica de PHP

PHP script para links no me funciona

Publicado por Joseba (56 intervenciones) el 15/12/2018 12:13:19
He encontrado , aunque mejor seria decir , me han ayudado a encontrarlo , porque no me funcionaba .
El problema estaba en CSS , el resto , estaba todo bien .
Yo escrivi en CSS ,
1
2
3
4
5
6
7
8
.link_wechsel a.[aria-current=page] {
 
 
 background-color:green;
 
 
 
}

cuando tenia que ser ,

1
2
3
4
5
6
7
8
.link_wechsel a[aria-current=page] {
 
 
background-color:green;
 
 
 
}

Era el punto , que me hacia , que no me funcionase el cambio de color...porque aria-current=page un attribute es https://tink.uk/using-the-aria-current-attribute/ , al Tag a , no tenia que haver puesto el punto https://tink.uk/using-the-aria-current-attribute/...

un Screeshot come me sale ahora... https://i.imgur.com/S7yd5g5.png
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar