Recent Topics

problem getting prev selected category on single-post page

Started by on Feb 29, 2008 – Contents updated: Feb 29, 2008

Feb 29, 2008 23:15    

...from a thread over on the Site Showcase forum (,

I didn't think that a chosen category carried over to a single post display (a permalink). EdB said it still had the criteria (see quotes below), but I see no sign of it!

I have the following code in my display of any page, multi or single:

      echo "cat debug\n" . "<br/>";
      echo "catsel=<";
      if ( isset( $GLOBALS[ 'catsel' ] ) && count ( $GLOBALS[ 'catsel' ] ) > 0 ) 
         echo "catsel=" . implode( ", ", $GLOBALS[ 'catsel' ] ); 
      echo ">,<br/>\n cat=<";
      if ( isset( $GLOBALS[ 'cat' ] ) ) echo $GLOBALS[ 'cat' ];
      echo ">,<br/>\n cats=<";
      if ( isset( $GLOBALS[ 'cats' ] ) ) echo $GLOBALS[ 'cats' ];
      echo ">,<br/>\n types=<";
      if ( isset( $GLOBALS[ 'types' ] ) ) echo $GLOBALS[ 'types' ];
      echo "><br/>\n";

For a multi-post page, I get:


cat debug

After selecting a permalink, for a single post page, I get:


cat debug

The permalink shows up in the permalink and address bar as


Any ideas?

(Details below)

- Cindy Rae


EdB wrote:

Next, clicking on a permalink gets you something like

and you lose the root category and type selection.

Actually that's not totally true, but not the big issue with no navigation from a single post page. The post itself still has all the criteria that got it to be the result of a filtered search - just not obvious in the URL. You can change how the URLs look to see what I mean on your Blog settings->pick a blog->URLs subtab, then change them back to nice looking URLs.

Feb 29, 2008 23:32

The POST - not the URL - is in a category that got it to be part of a multi-post page, and each post knows it's own categories. I don't have files open right now so I'm winging this a bit, but I have this feeling it'll jog you in the right direction.

Basically when the page is actually creating the post it is quite capable of echoing it's categories. Using the categories() function you can tell it to only list the main cat, or only the sub-cats, or the other form of cats (which I never did understand what that means), or any combination of them. So I'll guess something like $Item->get(categories) will return an array of the categories. Or you might have to work at extracting main_cat_ID if all you want is that level of detail.

But work at it from inside the post instead of by decoding the URL because yeah the URL for a permalink page embeds the information needed to make that post display, which is obviously not always the same as the information that caused that post to be part of a multi-post page.

One trick I used to do all the time is to print_r stuff to myself.

if( is_logged_in() ) { // always means only me on my blog
echo '<pre>$ITEM IS: ';
print_r( $Item );
echo '</pre>';

There have been times when I'd print_r so much different stuff just hunting around randomly that the page got to be like a million miles long, but sooner or later I'd find what I was after and tighten up whatever it was I was doing.

Anyway I probably said enough when I said "use the post instead of the URL" but I love to hear myself type :D

OT: Oh and hey adding a bit on the site showcase thread saying "go look at a different thread" doesn't really add value. Those of us who look anywhere tend to look everywhere in a language we can read yah?

Mar 04, 2008 16:54

I see what you're getting at, now -- you're talking about option #2, below.

Since no built-in way seems to exist for option #1, I can certainly do option #2 (I already am, in a way, to present the category list under the post title). In fact, I'll probably start working that up this week.

However, #2 is not ideal.

We're still talking about losing the context from the multi-page. Or, rather, changing the context once the user hits the single page then tries to go to another internal link. If I had only one-level categories, it wouldn't matter, but I have nested categories.

Details below, if you're interested in digging further.


Given the categories, "Wild Birds" --> "Attracting Wild Birds" --> "Feeding Wild Birds", and a link entry under "Feeding Wild Birds" called "A Link to Birdseed" ---

assume the user is sitting on a multiple-post page with the intermediate category, "Attracting Wild Birds", and no entry/post type selected (still "All") and clicks the permalink for the link entry.

I can go one of two directions:

-------- 1) Context from multi-post page.

The code knows what specific category ("Attracting Wild Birds") and type ("All") were selected that got us to the permalink.

Selected root category and selected type are based on the previous context. Links from the permalink page to other internal destinations preserve the context from the multi-post page (if you click on a category link in the post, it stays with the current entry/post type).

So, the "Wild Birds" and "All" tabs are selected, and internal links on the single-post page will display multiple posts the category set to "Attracting Wild Birds".

------- 2) Context from the single permalink page

The code determines the root category ("Wild Birds"), current category ("Feeding Wild Birds"), and post/entry type ("Link") from the one post being displayed. The code does not (cannot?) determine the intermediate category ("Attracting Wild Birds") that got the user here.

Selected root category and selected type tabs are based on the current context of the page.

...and either
(a) internal links on the single page preserve the type of entry and current category of the the single post
(b) internal links on the single page preserve the type of entry and root category of the the single post

(and other options I'll skip for brevity, since they don't make as much sense)

So, the "Wild Birds" and "Link" tabs are selected, and departing links have the category set to "Feeding Wild Birds".

Wondering why I had to come up with such an "interesting" skin, anyways,

- Cindy Rae

Form is loading...

Free CMS – This forum is powered by b2evolution CMS, a complete engine for your website.