Reply
What's wrong with this code?
Old 09-09-2009, 04:46 PM What's wrong with this code?
Skilled Talker

Posts: 96
Trades: 0
Hi guys,

I use wordpress and by default the tags in wordpress are ABC ordered and not ordered according to the order they were written in. So a friend wrote this code for me:

PHP Code:
function get_the_better_term_list$id 0$taxonomy 'post_tag'$before ''$sep ''$after '' ) {
    
$id = (int) $id;
    if ( ! 
$id && ! in_the_loop() )
        return 
false;
    if ( !
$id )
        
$id = (int) $post->ID;
    
$terms wp_get_object_terms($id$taxonomy, array('orderby' => 'term_order'));
    if ( 
is_wp_error$terms ) )
        return 
$terms;
    if ( empty( 
$terms ) )
        return 
false;
    foreach ( 
$terms as $term ) {
        
$link get_term_link$term$taxonomy );
        if ( 
is_wp_error$link ) )
            return 
$link;
        
$term_links[] = '<a href="' $link '" rel="tag">' $term->name '</a>';
    }
    
$term_links apply_filters"term_links-$taxonomy"$term_links );
    return 
$before join$sep$term_links ) . $after;
}
function 
the_better_tags$before 'Tags: '$sep ', '$after '' ){
    echo 
get_the_better_term_list(0'post_tag'$before$sep$after);

It's output is supposed to be displayed using this tag:

PHP Code:
<?php the_better_tags(); ?>

But it's not working, the area where the output is supposed to show is empty.

Can anyone see something wrong with this code?
Towhid is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 09-09-2009, 06:42 PM Re: What's wrong with this code?
vangogh's Avatar
Post Impressionist

Posts: 9,845
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
I think

term_links-$taxonomy

was supposed to be

term_links->$taxonomy
__________________
l Search Engine Friendly Web Design | Van SEO Design
l Tips On Marketing, SEO, Design, and Development | TheVanBlog
l Custom WordPress Themes
| Small Business Forum
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 09-09-2009, 07:43 PM Re: What's wrong with this code?
Skilled Talker

Posts: 96
Trades: 0
No, changing term_links-$taxonomy to term_links->$taxonomy didn't make any difference.
Towhid is offline
Reply With Quote
View Public Profile
 
Old 09-09-2009, 08:36 PM Re: What's wrong with this code?
NullPointer's Avatar
Will Code for Food

Latest Blog Post:
Apparatus Update Preview
Posts: 1,173
Name: Matt
Location: Irvine, CA
Trades: 0
$post is a global. To access it you need to explicitly declare
PHP Code:
global $post
I think.
__________________
Tinsology | How to Post Code | RosettaCodex
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 09-09-2009, 08:46 PM Re: What's wrong with this code?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,578
Name: Keith Marshall
Location: West Hartford, CT
Trades: 0
There is a lot we can't see in the example you provide.

There is a user defined function in_the_loop() that must be returning a false value. I also notice the use of an object $post that is not declared in the global scope.

So in the top of the function get_the_better_term_list() add the line:
global $post;
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 09-09-2009, 08:54 PM Re: What's wrong with this code?
Skilled Talker

Posts: 96
Trades: 0
None of that worked either, but don't worry about it, I found another solution to my original problem for which this code was written:

http://forum.bytesforall.com/showthread.php?t=2446 (last post)
Towhid is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to What's wrong with this code?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.09943 seconds with 13 queries