• Jackson Murphy

    (@jacksonm2factorycom)


    Hey someone…

    How would I dynamically get the Permalink using this code…

    <?php
    $categories = get_categories(‘exclude=9&title_li=’);
    foreach ($categories as $cat) {
    echo “<h2>“.$cat->cat_name.”</h2><p>”.$cat->category_description.”</p>”;
    }
    ?>

    I’m trying to dynamically list categories and the descriptions and the link… in a custom sidebar…

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Why not use wp_list_categories?

    Thread Starter Jackson Murphy

    (@jacksonm2factorycom)

    well, i don’t know… can i get the descriptions? and format the text/lnks?

    See the right side:
    https://springboard.com.s75811.gridserver.com/what-we-do/

    This is more or less hard coded right now…
    And please forgive any messed up stuff- I had to move the site from Yahoo today…

    Thread Starter Jackson Murphy

    (@jacksonm2factorycom)

    Does anyone know how to accomplish this?

    I had the same problem! I wanted to output my sidebar category links using this method instead of wp_list_categories so I could safely add a custom bullet on each <li>.

    To link each one, I used get_category_link with each specific cat_ID and it worked like a charm. Here is my loop:

    <li><h4>Categories</h4>
           <ul><?php $categories = get_categories();
    	 foreach ($categories as $cat) { ?>
    	    <li class="cat-item">&raquo; <a href="<?= get_category_link( $cat->cat_ID ); ?>"><?= $cat->cat_name; ?></a> <?= '('.$cat->category_count.')' ?></li>
       <?php } ?>
    	</ul>
    </li>

    Cheers!

    Thread Starter Jackson Murphy

    (@jacksonm2factorycom)

    Thanks Marcy-

    I actually found a PHP/Wordpress programmer to help me with this- We took it a step further by adding the description and changed the color of the link when active… Here’s the code we used…

    <?php
    
    	  $categories = get_categories('depth=1&hide_empty=false&exclude=9,18,27');
    
            foreach ($categories as $cat) {
    
             	 // Gets currently selected category id.
    			 $id = get_the_ID();
    		  	 $category = get_the_category($id);
    
    			 if($category[0]->cat_ID == $cat->cat_ID){
    			   if(!is_page()){ $link_color = 'style="color:#007fc2;"'; }
    
    				echo '<h2 ><a href="'.get_option('home').get_option('category_base').'/category/'.$cat->category_nicename.'/"' . $link_color . '>'.$cat->cat_name.'</a></h2>';
    			   }
    			 else{
    			   echo '<h2><a href="'.get_option('home').get_option('category_base').'/category/'.$cat->category_nicename.'/">'.$cat->cat_name.'</a></h2>';
    			}
    
                if ($cat->category_description != '') {
                    echo '<p>'.$cat->category_description.'</p>';
                }
    			else{
    	            echo '<p>&nbsp;</p>';
    			}
                if ($cat->category_parent != 0) {
                    echo '<p>&nbsp;</p>';
    
                }
            }
            ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How do I get the Permalink…?’ is closed to new replies.