Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    List Category IDs???

    Here is the page I'm trying to fix. I would like to change the code so that it only gathers specific category IDs rather than every category.

    Here is the code for that page:
    PHP Code:
    <div id="colFull">
            <?php 
            $current 
    get_the_category(); 
            
    $current_id$current[0] ->cat_ID
            
    $categs_list get_category_parents($current_id);
            
    $pieces explode("/"$categs_list);
            
    $category_name strtolower($pieces[0]);
            
    $categs get_cat_id($category_name);
            
    ?>

    <?php  if(is_category() && in_category($current_id) || post_is_in_descendant_category($current_id)){?>
            <h5><?php single_cat_title(); ?></h5>
            <ul class="portfolioCategs">
                <li><a href="<?php echo get_category_link(get_option('boldy_portfolio'))?>">All Guides</a></li>
                <?php    
                        $categories 
    get_categories('hide_empty=1&child_of='.$categs);
                        foreach (
    $categories as $cat) {
                        echo (
    '<li><a href="');
                        echo (
    get_category_link($cat->cat_ID).'">'.$cat->cat_name.'</a></li>');
                        }
                    
    ?>
            </ul>
        <?php ?>
    And here is a list of the category IDs I want to include: 6,7,8,9,10,11,12,13,16

    I tried solving the problem with the little coding help I received for my other list, but every time it goes to a blank page. Thanks so much for the help!!!

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,512
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    I thought I answered this post before ...
    Was I the one that gave you bad info ... where it didn't work?
    Let me know, and maybe we can try something else.

    The blank page means you have a scripting error and your
    error reporting is turned off. So it just displays "nothing".

    EDIT:
    So it was you that asked this before:
    http://www.codingforums.com/showthread.php?t=248780

    Please only post your questions/problems one time.
    If what I gave you didn't work, you should have let me know.

    Can you post what you tried ... the one that gave you a blank page?



    .
    Last edited by mlseim; 01-16-2012 at 07:26 PM.

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts
    This is a new problem.

    The solution you provided last time worked, but only on my blog. Apparently the "Guides" section has a different line of code. It makes the categories appear on top of a portfolio section and uses different script.

    I tried to adapt your code to work on the page, but I just don't know enough about it to make it work. I was able to substitute the right columned categories in for horizontal bar, but it just looked tacky so I decided I'd ask for help again.

    I've been attempting to modify/substitute this line of code:
    PHP Code:
    <?php echo get_cat_name(get_option('boldy_blog'));?>
    and this line:
    PHP Code:
    <ul >  
           <?wp_list_categories('include=6,7,8,9,10,11,12,13,16&title_li=');?> 
           </ul>
    to replace different parts in this:
    PHP Code:
    <?php 
            $current 
    get_the_category(); 
            
    $current_id$current[0] ->cat_ID
            
    $categs_list get_category_parents($current_id);
            
    $pieces explode("/"$categs_list);
            
    $category_name strtolower($pieces[0]);
            
    $categs get_cat_id($category_name);
            
    ?>
    Unfortunately, it just hasn't worked and my coding knowledge is non-existent so I'm not even sure if I'm modifying the right code, let alone what I'm doing wrong.
    Last edited by swedy13; 01-16-2012 at 07:42 PM.

  • #4
    New Coder
    Join Date
    Jan 2012
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Holy crap! Guess that saying about even blind squirrels finding nuts is true. I added:

    PHP Code:
    $categories get_categories('exclude=1,4,48,49,54='); 
    to...

    PHP Code:
    <?php    
                        $categories 
    get_categories('hide_empty=1&child_of='.$categs);
                        foreach (
    $categories as $cat) {
                        echo (
    '<li><a href="');
                        echo (
    get_category_link($cat->cat_ID).'">'.$cat->cat_name.'</a></li>');
                        }
                    
    ?>
    and shockingly it worked! Thanks for the CODEX pages and sorry for all the simple questions. I'm learning

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,512
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    No problem ... glad you got it working.

    WP has so many CODEX mashups, hacks, and other cool things to do.
    And remember to only make changes to your theme files. Because if you
    change any of the other WP files, they will be overwritten when you do
    a revision upgrade.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •