• Hi guys,

    I’m trying to get a list of sub-categories to display on a page when the parent category is clicked on.

    I managed to get the sub-categories listed, but I can’t get the links on those sub-categories to point to the sub-category URL.

    Is there a get_option that will allow me to retrieve the URL/permalink of that sub-category?

    Here’s the code I’m using.

    `
    <?php
    $categories = get_categories(‘child_of=1&orderby=ID&hide_empty=0’);
    foreach ($categories as $cat) {
    if ($cat->category_parent != 0) {
    echo ‘<span style=”padding-left:10px;”>’;
    }
    echo ‘<div class=”title-insert main-post-bg-a showhero”>
    <h2>category_nicename.’/”>’.$cat->cat_name.’</h2>
    </div> ‘;
    echo ‘
    ‘;
    }
    ?>
    `

    Please advice!

    Thanks

Viewing 1 replies (of 1 total)
  • Thread Starter Kai2810

    (@kai2810)

    Please ignore the above post…I was trying to get the code to be displayed with b-quotes.

    Here’s the code I’m having trouble with.

    <?php
    $categories = get_categories('child_of=1&orderby=ID&hide_empty=0');
    foreach ($categories as $cat) {
    	if ($cat->category_parent != 0) {
    		echo '<span style="padding-left:10px;">';
    	}
    	echo '<div class="title-insert main-post-bg-a showhero">
            <h2><a href="'.get_option('home').get_option('category_base').'/'.$cat->category_nicename.'/">'.$cat->cat_name.'</a></h2>
    </div> ';
    	echo '<br />';
    }
    ?>

    Please advice!

Viewing 1 replies (of 1 total)
  • The topic ‘Use get_option to retrieve url of category?’ is closed to new replies.