Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Wordpress] Dostęp do listy kategorii
Vill
post
Post #1





Grupa: Zarejestrowani
Postów: 62
Pomógł: 0
Dołączył: 22.05.2009

Ostrzeżenie: (0%)
-----


Mam listę kategorii pobraną w ten sposób:

  1. $categories = get_categories( array('type' => 'post') );


Jak się dostać to poszczególnych elementów tablicy po indeksie? Dla testów wypisuje sobie nazwy kategorii w pętli foreach, z tym nie ma żadnych problemów, wypisuje się jak trzeba.

  1. foreach ($categories as $cat) {
  2. echo $cat->name;
  3. }


Problem pojawia się jak próbuję dostać się do tej tablicy po indeksie

  1. echo $categories[0]->name;
  2. echo $categories[1]->name;
  3. echo $categories[2]->name;


Wypisuje się tylko kategoria z indeksem 0. Te z indeksem 1 i 2 się nie wypisują. Jak się dostać do tych elementów? get_categories() zwraca tablicę obiektów.




Ten post edytował Vill 5.09.2014, 11:55:59
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
pedro84
post
Post #2





Grupa: Nieautoryzowani
Postów: 2 249
Pomógł: 305
Dołączył: 2.10.2006

Ostrzeżenie: (0%)
-----


Tutaj masz link do Codexa. Ta pętla musi działać.

Pokaż output z
  1. var_dump($categories)
Go to the top of the page
+Quote Post
Vill
post
Post #3





Grupa: Zarejestrowani
Postów: 62
Pomógł: 0
Dołączył: 22.05.2009

Ostrzeżenie: (0%)
-----


Cytat(pedro84 @ 5.09.2014, 12:46:35 ) *
Tutaj masz link do Codexa. Ta pętla musi działać.

Pokaż output z
  1. var_dump($categories)



Cytat
array (size=3)
0 =>
object(stdClass)[1759]
public 'term_id' => &string '1' (length=1)
public 'name' => &string 'Bez kategorii' (length=13)
public 'slug' => &string 'bez-kategorii' (length=13)
public 'term_group' => string '0' (length=1)
public 'term_taxonomy_id' => string '1' (length=1)
public 'taxonomy' => string 'category' (length=8)
public 'description' => &string '' (length=0)
public 'parent' => &string '0' (length=1)
public 'count' => &string '1' (length=1)
public 'cat_ID' => &string '1' (length=1)
public 'category_count' => &string '1' (length=1)
public 'category_description' => &string '' (length=0)
public 'cat_name' => &string 'Bez kategorii' (length=13)
public 'category_nicename' => &string 'bez-kategorii' (length=13)
public 'category_parent' => &string '0' (length=1)
2 =>
object(stdClass)[1761]
public 'term_id' => &string '2' (length=1)
public 'name' => &string 'Kategoria 1' (length=11)
public 'slug' => &string 'kategoria1' (length=10)
public 'term_group' => string '0' (length=1)
public 'term_taxonomy_id' => string '2' (length=1)
public 'taxonomy' => string 'category' (length=8)
public 'description' => &string '' (length=0)
public 'parent' => &string '0' (length=1)
public 'count' => &string '1' (length=1)
public 'cat_ID' => &string '2' (length=1)
public 'category_count' => &string '1' (length=1)
public 'category_description' => &string '' (length=0)
public 'cat_name' => &string 'Kategoria 1' (length=11)
public 'category_nicename' => &string 'kategoria1' (length=10)
public 'category_parent' => &string '0' (length=1)
3 =>
object(stdClass)[1762]
public 'term_id' => &string '4' (length=1)
public 'name' => &string 'Kategoria 2' (length=11)
public 'slug' => &string 'kategoria2' (length=10)
public 'term_group' => string '0' (length=1)
public 'term_taxonomy_id' => string '4' (length=1)
public 'taxonomy' => string 'category' (length=8)
public 'description' => &string '' (length=0)
public 'parent' => &string '0' (length=1)
public 'count' => &string '2' (length=1)
public 'cat_ID' => &string '4' (length=1)
public 'category_count' => &string '2' (length=1)
public 'category_description' => &string '' (length=0)
public 'cat_name' => &string 'Kategoria 2' (length=11)
public 'category_nicename' => &string 'kategoria2' (length=10)
public 'category_parent' => &string '0' (length=1)
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 29.12.2025 - 11:13