Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

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

Posts: 101
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
 
 
Register now for full access!
Old 09-09-2009, 07:42 PM Re: What's wrong with this code?
vangogh's Avatar
Post Impressionist

Posts: 10,688
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 |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 09-09-2009, 08:43 PM Re: What's wrong with this code?
Super Talker

Posts: 101
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, 09:36 PM Re: What's wrong with this code?
NullPointer's Avatar
Will Code for Food

Posts: 2,781
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.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 09-09-2009, 09:46 PM Re: What's wrong with this code?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
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, 09:54 PM Re: What's wrong with this code?
Super Talker

Posts: 101
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.23900 seconds with 12 queries