Wordpress, php, and css question (help me please)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tonyparra
    Confirmed User
    • Jul 2008
    • 4568

    #1

    Wordpress, php, and css question (help me please)

    Hello. Im trying to style the wp_list_categories tag (<?php

    wp_list_categories('arg'); ?>). i know that i can style it using an unordered list and css. Something like this:

    <ul class="cat_list"><?php

    wp_list_categories('show_count=1&hide_empty=1&titl e_li=<h2>Categories</

    h2>'); ?></ul>

    That will print a list of categories, hide categories with zero post, and show title called "categories". What i would like to do though is make the parent category links look different from the child category links (have a different font size or use <h3> tag for parent category), so i how would i do that? Like i said I know how to style whole list but how can I make this customization happen? Or is it not possible? Thanks for any help.
    Last edited by tonyparra; 06-17-2010, 08:15 PM.

    High Performance Vps $10 Linode
    Manage your Digital Ocean, Linode, or Favorite Cloud Server. Simple, fast, and secure Server Pilot
  • tonyparra
    Confirmed User
    • Jul 2008
    • 4568

    #2
    bumperoo

    High Performance Vps $10 Linode
    Manage your Digital Ocean, Linode, or Favorite Cloud Server. Simple, fast, and secure Server Pilot

    Comment

    • mattz
      Confirmed User
      • Dec 2001
      • 7697

      #3
      bump for ya

      Comment

      • harvey
        Confirmed User
        • Jul 2001
        • 9266

        #4
        well, I don't have an example with categories and subcategories at hand (oh my, why in hell every single person asking for help NEVER includes the example so they can actually be helped?) but if you constructed it using defaults you should have something like

        Code:
        <ul>
        <li>Cat 1</li>
        <li>Cat2
             <ul>
                  <li> Cat 2 Children category </li>
             </ul>
        </li>
        </ul>
        where
        Code:
        <li> Cat 2 Children category </li>
        will have a class named .children or .child or something like that (don't remember right now, and since nobody post examples.... ). Just style that class and you'll be done
        This post is endorsed by CIA, KGB, MI6, the Mafia, Illuminati, Kim Jong Il, Worldwide Ninjas Association, Klingon Empire and lolcats. Don't mess around with it, just accept it and embrace the truth

        Comment

        • tonyparra
          Confirmed User
          • Jul 2008
          • 4568

          #5
          Originally posted by harvey
          well, I don't have an example with categories and subcategories at hand (oh my, why in hell every single person asking for help NEVER includes the example so they can actually be helped?) but if you constructed it using defaults you should have something like

          Code:
          <ul>
          <li>Cat 1</li>
          <li>Cat2
               <ul>
                    <li> Cat 2 Children category </li>
               </ul>
          </li>
          </ul>
          where
          Code:
          <li> Cat 2 Children category </li>
          will have a class named .children or .child or something like that (don't remember right now, and since nobody post examples.... ). Just style that class and you'll be done

          sorry i was tired when i made thread...the wp_list_categories prints your category list heres a snippet of code from the default wordpress theme sidebar:
          Code:
          <?php wp_list_categories('show_count=1&title_li=<h2>Categories</h2>'); ?>
          that will print a list in alphabetical order with child categories, and post count. An example of what i currently have can be found in the default wp theme, an example of what i would like my list to look like can be found here:
          http://www.hotmovies.com/categories.php
          The parent cats are bold and using the <h3> tag, therefore helping to show the difference between parent and child cats. Is that possible in wordpress?

          High Performance Vps $10 Linode
          Manage your Digital Ocean, Linode, or Favorite Cloud Server. Simple, fast, and secure Server Pilot

          Comment

          • tonyparra
            Confirmed User
            • Jul 2008
            • 4568

            #6
            bump for me

            High Performance Vps $10 Linode
            Manage your Digital Ocean, Linode, or Favorite Cloud Server. Simple, fast, and secure Server Pilot

            Comment

            • cyber
              Confirmed User
              • Jan 2004
              • 182

              #7
              Code:
              $sql = "SELECT name,slug,$wpdb->terms.term_id as ID,parent FROM $wpdb->terms ".
                     "LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id) ".
                     "WHERE parent=5 AND taxonomy='category' ORDER BY name ASC";
              $categoryList = $wpdb->get_results($sql);
              
              echo categoryPrint($categoryList);
              
              
              
              function categoryPrint($results, $multiple = "", $subcat_level = 0){
                global $wpdb;
                if(!$results){return;}
                foreach($results as $a_cat){
                  if($multiple){
                    categoryPrintSelectItem($a_cat, $subcat_level);
                  }
                  else{
                    categoryPrintItem($a_cat, $subcat_level);
                  }
                  $sql = "SELECT name,slug,$wpdb->terms.term_id as ID,parent FROM $wpdb->terms ".
                         "LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id) ".
                         "WHERE parent=$a_cat->ID AND taxonomy='category' ORDER BY name ASC";
                  $sub_cats = $wpdb->get_results($sql); 
                  categoryPrint($sub_cats, $multiple, $subcat_level + 1);
                }
              }
              function categoryPrintSelectItem($a_cat, $subcat_level){
                for($i = 0; $i < $subcat_level; $i++){
                  echo "…";
                }
                echo $a_cat->name."</option>\n";
              }
              function categoryPrintItem($a_cat, $subcat_level){
                for($i = 0; $i < $subcat_level; $i++){
                  echo "{$a_cat->name}<br>";
                }
                if($subcat_level < 1){
                  echo "<b><h3>{$a_cat->name}</h3></b><br>";
                }
              }
              Change this:

              Code:
              WHERE parent=5
              To the category's ID.

              Comment

              • fris
                Too lazy to set a custom title
                • Aug 2002
                • 55679

                #8
                Originally posted by cyber
                Code:
                $sql = "SELECT name,slug,$wpdb->terms.term_id as ID,parent FROM $wpdb->terms ".
                       "LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id) ".
                       "WHERE parent=5 AND taxonomy='category' ORDER BY name ASC";
                $categoryList = $wpdb->get_results($sql);
                
                echo categoryPrint($categoryList);
                
                
                
                function categoryPrint($results, $multiple = "", $subcat_level = 0){
                  global $wpdb;
                  if(!$results){return;}
                  foreach($results as $a_cat){
                    if($multiple){
                      categoryPrintSelectItem($a_cat, $subcat_level);
                    }
                    else{
                      categoryPrintItem($a_cat, $subcat_level);
                    }
                    $sql = "SELECT name,slug,$wpdb->terms.term_id as ID,parent FROM $wpdb->terms ".
                           "LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id) ".
                           "WHERE parent=$a_cat->ID AND taxonomy='category' ORDER BY name ASC";
                    $sub_cats = $wpdb->get_results($sql); 
                    categoryPrint($sub_cats, $multiple, $subcat_level + 1);
                  }
                }
                function categoryPrintSelectItem($a_cat, $subcat_level){
                  for($i = 0; $i < $subcat_level; $i++){
                    echo "?";
                  }
                  echo $a_cat->name."</option>\n";
                }
                function categoryPrintItem($a_cat, $subcat_level){
                  for($i = 0; $i < $subcat_level; $i++){
                    echo "{$a_cat->name}<br>";
                  }
                  if($subcat_level < 1){
                    echo "<b><h3>{$a_cat->name}</h3></b><br>";
                  }
                }
                Change this:

                Code:
                WHERE parent=5
                To the category's ID.
                thats a sure messy way to do it, when you can do it with css.

                have a look at the default wordpress css styling, theirs one for child cats.

                http://digwp.com/2010/05/default-wor...-styles-hooks/
                Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

                Comment

                • cyber
                  Confirmed User
                  • Jan 2004
                  • 182

                  #9
                  Originally posted by fris
                  thats a sure messy way to do it, when you can do it with css.

                  have a look at the default wordpress css styling, theirs one for child cats.

                  http://digwp.com/2010/05/default-wor...-styles-hooks/
                  I repurposed to code from a page of mine that prints out the categories in form select fields for something totally different.

                  Figured this would get the job done without telling him what CSS styles he needed to change ;)

                  Comment

                  • tonyparra
                    Confirmed User
                    • Jul 2008
                    • 4568

                    #10
                    Originally posted by fris
                    thats a sure messy way to do it, when you can do it with css.

                    have a look at the default wordpress css styling, theirs one for child cats.

                    http://digwp.com/2010/05/default-wor...-styles-hooks/
                    hmm so are you saying style the child cats maybe i can bold the parents im having a hard time putting that together though can you help me out?

                    High Performance Vps $10 Linode
                    Manage your Digital Ocean, Linode, or Favorite Cloud Server. Simple, fast, and secure Server Pilot

                    Comment

                    • tonyparra
                      Confirmed User
                      • Jul 2008
                      • 4568

                      #11
                      this may require custom solution it seems...

                      High Performance Vps $10 Linode
                      Manage your Digital Ocean, Linode, or Favorite Cloud Server. Simple, fast, and secure Server Pilot

                      Comment

                      • harvey
                        Confirmed User
                        • Jul 2001
                        • 9266

                        #12
                        Originally posted by tonyparra
                        sorry i was tired when i made thread...the wp_list_categories prints your category list heres a snippet of code from the default wordpress theme sidebar:
                        Code:
                        <?php wp_list_categories('show_count=1&title_li=<h2>Categories</h2>'); ?>
                        that will print a list in alphabetical order with child categories, and post count. An example of what i currently have can be found in the default wp theme, an example of what i would like my list to look like can be found here:
                        http://www.hotmovies.com/categories.php
                        The parent cats are bold and using the <h3> tag, therefore helping to show the difference between parent and child cats. Is that possible in wordpress?
                        yes, I know you used that hook, I just shown you the output. So here you have since your code is outputting something different to what it should be (not your fault, probably a change in WP, you're using the correct function as documented):

                        Code:
                        <?php $sub_cat =  wp_list_categories('echo=0&amp;orderby=name&amp;title_li=&amp;hierarchical=0&amp;child_of='.$category->cat_ID); ?>
                        	<ul class="subcat"><?php echo $sub_categories; ?></ul>
                        <?php } ?>
                        This post is endorsed by CIA, KGB, MI6, the Mafia, Illuminati, Kim Jong Il, Worldwide Ninjas Association, Klingon Empire and lolcats. Don't mess around with it, just accept it and embrace the truth

                        Comment

                        • fris
                          Too lazy to set a custom title
                          • Aug 2002
                          • 55679

                          #13
                          hit me up on icq 704-299 ill see if i can sort you out
                          Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

                          Comment

                          • Deej
                            I make pixels work
                            • Jun 2005
                            • 24386

                            #14
                            Watch out... I ICQ'd Fris once and all the sudden my dog died.

                            ICQ at your own risk...

                            Deej's Designs n' What Not
                            Hit me up for Design, CSS & Photo Retouching


                            Icq#30096880

                            Comment

                            Working...