SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Addict
    Join Date
    Jul 2003
    Location
    Toronto, Ontario
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation // Moving Number Left

    Hello,

    I've been working on modifying a wordpress template and have run into a small issue.

    There is a function that looks like this...

    Code:
    function wp_list_categories($args = '') {
    	$defaults = array(
    		'show_option_all' => '', 'orderby' => 'name',
    		'order' => 'ASC', 'show_last_update' => 0,
    		'style' => 'list', 'show_count' => 0,
    		'hide_empty' => 1, 'use_desc_for_title' => 1,
    		'child_of' => 0, 'feed' => '', 'feed_type' => '',
    		'feed_image' => '', 'exclude' => '', 'current_category' => 0,
    		'hierarchical' => true, 'title_li' => __('Categories'),
    		'echo' => 1, 'depth' => 0
    	);
    Where the output gives you Category(Count) but I want it to output (Count)Category instead (I just want the count to appear ont he left rather then the right). Can anybody help me figure out if it is possible to change something in this function to allow Count to come first?

    Thank you for looking,
    Mario
    $ Available For Hire
    Need a website designed or coded? Then feel free to contact me!

    PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net

  2. #2
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ethics View Post
    Hello,

    I've been working on modifying a wordpress template and have run into a small issue.

    There is a function that looks like this...

    Code:
    function wp_list_categories($args = '') {
    	$defaults = array(
    		'show_option_all' => '', 'orderby' => 'name',
    		'order' => 'ASC', 'show_last_update' => 0,
    		'style' => 'list', 'show_count' => 0,
    		'hide_empty' => 1, 'use_desc_for_title' => 1,
    		'child_of' => 0, 'feed' => '', 'feed_type' => '',
    		'feed_image' => '', 'exclude' => '', 'current_category' => 0,
    		'hierarchical' => true, 'title_li' => __('Categories'),
    		'echo' => 1, 'depth' => 0
    	);
    Where the output gives you Category(Count) but I want it to output (Count)Category instead (I just want the count to appear ont he left rather then the right). Can anybody help me figure out if it is possible to change something in this function to allow Count to come first?

    Thank you for looking,
    Mario


    You didn't include the entire function, most notably the return statement.
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  3. #3
    SitePoint Addict
    Join Date
    Jul 2003
    Location
    Toronto, Ontario
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, didn't realize the function was that large.

    Code:
    function wp_list_categories($args = '') {
    	$defaults = array(
    		'show_option_all' => '', 'orderby' => 'name',
    		'order' => 'ASC', 'show_last_update' => 0,
    		'style' => 'list', 'show_count' => 0,
    		'hide_empty' => 1, 'use_desc_for_title' => 1,
    		'child_of' => 0, 'feed' => '', 'feed_type' => '',
    		'feed_image' => '', 'exclude' => '', 'current_category' => 0,
    		'hierarchical' => true, 'title_li' => __('Categories'),
    		'echo' => 1, 'depth' => 0
    	);
    
    	$r = wp_parse_args( $args, $defaults );
    
    	if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
    		$r['pad_counts'] = true;
    	}
    
    	if ( isset( $r['show_date'] ) ) {
    		$r['include_last_update_time'] = $r['show_date'];
    	}
    
    	extract( $r );
    
    	$categories = get_categories($r);
    
    	$output = '';
    	if ( $title_li && 'list' == $style )
    			$output = '<li class="categories">' . $r['title_li'] . '<ul>';
    
    	if ( empty($categories) ) {
    		if ( 'list' == $style )
    			$output .= '<li>' . __("No categories") . '</li>';
    		else
    			$output .= __("No categories");
    	} else {
    		global $wp_query;
    
    		if( !empty($show_option_all) )
    			if ('list' == $style )
    				$output .= '<li><a href="' .  get_bloginfo('url')  . '">' . $show_option_all . '</a></li>';
    			else
    				$output .= '<a href="' .  get_bloginfo('url')  . '">' . $show_option_all . '</a>';
    
    		if ( empty( $r['current_category'] ) && is_category() )
    			$r['current_category'] = $wp_query->get_queried_object_id();
    
    		if ( $hierarchical )
    			$depth = $r['depth'];
    		else
    			$depth = -1; // Flat.
    
    		$output .= walk_category_tree($categories, $depth, $r);
    	}
    
    	if ( $title_li && 'list' == $style )
    		$output .= '</ul></li>';
    
    	$output = apply_filters('wp_list_categories', $output);
    
    	if ( $echo )
    		echo $output;
    	else
    		return $output;
    }
    Thanks,
    Mario
    $ Available For Hire
    Need a website designed or coded? Then feel free to contact me!

    PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net

  4. #4
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you provide some sample output, including the HTML?
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  5. #5
    SitePoint Addict
    Join Date
    Jul 2003
    Location
    Toronto, Ontario
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the output reference guide for that particular function...

    http://codex.wordpress.org/Template_...ist_categories

    And here is an example of what is being outputted...

    http://idesigniphone.com/

    Thanks,
    Mario
    $ Available For Hire
    Need a website designed or coded? Then feel free to contact me!

    PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net

  6. #6
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you pass any arguments to wp_list_categories()? Can you show the code around where you call it?
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  7. #7
    SitePoint Addict
    Join Date
    Jul 2003
    Location
    Toronto, Ontario
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    			<div id="navigation_container">
    				<a href="#" class="homepage_reservations_rollover"><div class="float_left">All Wallpapers</div><div class="float_right"><?php the_category_count(1); ?></div></a>
    				<div id="category_divider"></div>
                    <?php
                    $variable = wp_list_categories('echo=0&show_count=1&exclude=1&title_li=');
    				$variable = str_replace(array('(',')'), '', $variable);
    				echo $variable;
    				?>
                </div>
    $ Available For Hire
    Need a website designed or coded? Then feel free to contact me!

    PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net

  8. #8
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It looks like that functionality is built deeper in one of the WP libraries.

    You could use a preg_replace similar to the str_replaced you've used.

    PHP Code:
    $variable preg_replace(
        
    '/(<li[^<>]*>)\s*(<a[^<>]*>\w*<\/a>)\s*(\(\d*\))\s+(<\/li>)/i',
        
    '${1}${3} ${2}${4}',
        
    $variable 
    );
    $variable str_replace... 
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  9. #9
    SitePoint Addict
    Join Date
    Jul 2003
    Location
    Toronto, Ontario
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for taking the time to look over all that code. For now I have used some css styling to position the numbers and the links where I want them.

    This method was quite messy so I'm going to try your method and see if it works.

    Thanks again,
    Mario
    $ Available For Hire
    Need a website designed or coded? Then feel free to contact me!

    PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net

  10. #10
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    It might be a better idea to create a filter and put it into your theme's functions.php file.

    PHP Code:
    /*
        Moves the post count from right to left in the 
        output from wp_list_categories
    */
    add_filter('wp_list_categories''filter_list_categories_count');
    function 
    filter_list_categories_count($input)
    {
        return 
    preg_replace('~(<a[^>]*>.*?</a>) \((\d+)\)~i''($2) $1'$input);

    Salathe
    Software Developer and PHP Manual Author.


Bookmarks

Posting Permissions

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