On these pages are my WordPress plugins, the odd article and my Support Forum.

For my random rantings on everything else please visit my blog at Yellow Swordfish

WP Plugins


Articles

If you find any of my plugins useful, please comsider a donation towards my running costs.

Thank you

Current User: Guest
Please consider registering

 
Search Forums:


 




category mess

UserPost

8:51 pm
18 Oct 2007


proper

Guest

 
1

I am trying to mix categories, pages and posts to form up a portal-like site. Something that seemed out to be pretty impossible until I found the plugin.

 The topmost sections of my site are represented by pages. So after installing the plugin I first assigned my top pages to the proper categories. Each of the top pages queries posts within the $cat category, which sould in theory return the posts assigned to the same category. And the sub-navigation uses wp_list_categories with child_of $cat to list subcategories within the category. And that’s where I noticed it just does not work - the $cat does not return anything. So instead of getting list of posts within the category I get a totally messed list of posts and the list of categories mixes up all categories of the same level and their subcategories. And it does not make difference whether I use $cat in the loop or not. So I started thinking - is it a bug in the plugin, or WordPress just can’t handle the idea of pages being assigned to categories and calling the $cat identifier. I thought the plugin might come up with a function that returns the ID of the current category instead of $cat, but as it seems it does not. So any ideas what the possible cause and fix might be? Thanks in advance.

9:13 pm
18 Oct 2007


Yellow Swordfish

Admin

Peterborough, England

posts 4481

 
2

Well I’ve read this through three times now and I am still confused. What is ‘$cat’ and where are you getting it from? Are you assigning this variable yourself? And what is missing from wp_list_categories()?

9:41 pm
18 Oct 2007


proper

Guest

 
3

AFAIK $cat is the general WordPress variable that should return the category current post is placed under.

10:23 pm
18 Oct 2007


Yellow Swordfish

Admin

Peterborough, England

posts 4481

 
4

It’s a new one on me. I am not aware of any variable that does this. You may be right but of course and I’d welcome knowing more.

10:52 pm
18 Oct 2007


Mr Papa

Moderator

Arizona, USA

posts 1167

 
5

Andy, quick reference on $cat 

http://wordpress.taragana.net/_variables/cat.html

in core wp, pages dont have categories, so I would imagine that variable is empty 

10:54 pm
18 Oct 2007


Mr Papa

Moderator

Arizona, USA

posts 1167

 
6

argh, link isnt quite right… scroll down to $cat and select… then you will see all the settings and references…  links take your right to the code…

11:22 pm
18 Oct 2007


Yellow Swordfish

Admin

Peterborough, England

posts 4481

 
7

Oh yes - $cat is a common variable used within the core. I was realy asking how it was exposed in a theme template. It’s only going to be available by using some function or other and that’s the important bit really.

But thanks for the list. That’s a useful resource! You certanly know you’re way around!

11:53 pm
18 Oct 2007


Mr Papa

Moderator

Arizona, USA

posts 1167

 
8

you should be able to get at $cat in a theme within the loop and just adding a global $cat statement before trying to use it… of course, I haven’t tried it… Tongue out  I have tried it with other "global" wp core variables…

12:12 am
19 Oct 2007


Yellow Swordfish

Admin

Peterborough, England

posts 4481

 
9

As far as I can see $cat is only ever defined as a global in the function category_description() although I may well have missed it elsewhere. I rather think that;s a bit odd as well as it serves no purpose.

Of course creating a variable to hold the cat(s) is not difficult but as to the original question I would very much like to see how it is being done.

12:50 am
19 Oct 2007


Yellow Swordfish

Admin

Peterborough, England

posts 4481

 
10

Double-checked. $Cat is NOT available as a filled variable in  the loop rather as I suspected.

8:38 am
19 Oct 2007


proper

Guest

 
11

I am trying to explain something utterfly difficult and complex (IMO) with my poor English, so I am sorry about that.

Basicaly the site structure looks like this:

Pages (assigned to categories)
- Posts (assigned to subcategories in the respective page category)

So my category structure looks like:

Resources
- Articles
- Press release
- News

and I have a page called Resources assigned to the resources category, and posts in Articles, Press release and News. I thought that would be the most convenient way for me to organize pages and posts.

As my PHP skills are close to zero, I am mostly trying to solve my problems just testing different ways. I am using WP as CMS platform for lots of projects and I have some skills already, but this project is something different.

In this case my loop in the page looks like this (pretty standard):

‘, ‘excerpt’, false, ”, false, 2, true); ?>

And my sidenav (that should display subcategories for the category where the page is assigned), looks like this:


foreach((get_the_category()) as $category)
echo ("

    ");
    wp_list_categories("orderby=sort_column&hierarchical=0&depth=1&title_li=&child_of=" . $category->category_parent . "" );
    echo ("

");
?>


… but it always returns just the first category subcategories.

Now when I think of it, you will probably be able to get the whole picture if I just send you the page template instead?

9:36 am
19 Oct 2007


proper

Guest

 
12

Now, when I tested it a bit more, having a

<?php foreach((get_the_category()) as $cat) ?>

before the call seems to be fixing it.

10:51 am
19 Oct 2007


Yellow Swordfish

Admin

Peterborough, England

posts 4481

 
13

OK…. So problem solved yes?



Reply to Topic: category mess

NOTE: New Posts are subject to administrator approval before being displayed

Guest Name (Required):

Guest EMail (Required):

Guest URL (required)

Math Required!
What is the sum of: 10 + 8        (Required)

Topic Reply:


 
 

About the Stuff at Yellow Swordfish forum

Currently Online:

sju

10 Guests

Maximum Online: 71

Forums:

Groups: 3

Forums: 15

Topics: 1703

Posts: 11495

Members:

There are 780 members

There are 729 guests


Yellow Swordfish has made 4481 posts

Top Posters:

Mr Papa - 1167

-Radio- - 475

ovizii - 84

jfv - 80

angelic007 - 66

Administrator: Yellow Swordfish | Moderators: Yellow Swordfish, Mr Papa, -Radio-


© Simple:Press Forum - Version 3.1.3 (Build 356)