Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Bit of Wordpress Help (URGENT!)

Featured Replies

Alright guru's!

 

I need some help.

 

I have a two tiered navigation structure on a site for work; one is the main navigation, and when the user selects that, they see ALL posts within that and all sub categories, now that is working fine. What I need to do, is in a sidebar, to list all sub-categories of the selected category.

 

At the moment I have:

 

<?php wp_list_categories('title_li=&child_of=3'); ?>

 

But I need to make 'child_of' the current category in the URL - does that makes sense?

 

Ta

 

Tel

  • Author

Hi Jay,

 

Yes I have had a look - I have the category stored in a variable, but how do I input that as an argument?

 

I currently have:

 

<?php wp_list_categories('title_li=&child_of=$parent'); ?>

 

But that isn't working :fool:

 

Help :)

Very close my friend. Just need to change the single quotes to double quotes or concatenate the parent to the string

first method

<?php wp_list_categories("title_li=&child_of=$parent"); ?>

second method

<?php wp_list_categories('title_li=&child_of='.$parent); ?>

Personally I would go for the second method. I'm not a fan of putting variables directly into strings, but either will work

  • Author

Argh - bugger! Sorry Jay, one more question mate...

 

I am using this code to get the parent category:

 

<?php
$category = get_the_category(); 
$cats = $category[0]->term_id;
echo $cats;
?>

 

BUT the problem is, it is pulling the categories into the array in alphabetic order, rather than numerical order... or just the highest ranking (or parent) page - any idea how I would tell the array to do it in number order instead of alpha?

 

Cheers

Can you put the following after your first line and paste the output here so that I know what the array looks like

echo '<pre>'.print_r($category, true).'</pre>';

  • Author

Sure - here you go:

 

(
   [0] => stdClass Object
       (
           [term_id] => 29
           [name] => Charity Performance
           [slug] => charityperformance
           [term_group] => 0
           [term_taxonomy_id] => 29
           [taxonomy] => category
           [description] => 
           [parent] => 3
           [count] => 1
           [object_id] => 1
           [cat_ID] => 29
           [category_count] => 1
           [category_description] => 
           [cat_name] => Charity Performance
           [category_nicename] => charityperformance
           [category_parent] => 3
       )

   [1] => stdClass Object
       (
           [term_id] => 3
           [name] => Homepage
           [slug] => anthony-nolan
           [term_group] => 0
           [term_taxonomy_id] => 3
           [taxonomy] => category
           [description] => 
           [parent] => 0
           [count] => 4
           [object_id] => 1
           [cat_ID] => 3
           [category_count] => 4
           [category_description] => 
           [cat_name] => Homepage
           [category_nicename] => anthony-nolan
           [category_parent] => 0
       )

)

$category = get_the_category();
$term = 9999999;
foreach($category as $cat) {
$term = ($cat->term_id < $term) ? $cat->term_id ? $term;
}
echo $term;

Try that

  • Author

Sorry dude:

 

I got this...

 

Parse error: syntax error, unexpected ';' in C:\Program Files\xampp\htdocs\intranet\wp-content\themes\greenroom\sidebar.php on line 5

 

Line 5:

 

$term = ($cat->term_id < $term) ? $cat->term_id ? $term;

 

:unknw:

  • Author

:clapping: :clapping: :clapping: :clapping:

 

Thank you dude!!

 

It works :D

 

Cheers

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.