• Resolved petitpoulain

    (@petitpoulain)


    I’m usind in_category inside get_posts on my sidebar. But some wordpress tags(the_permalink and the_title) appear first than the html code

    The PHP code

    <?php
    $posts = get_posts('numberposts=10&offset=1');
    foreach($posts as $post) :
    setup_postdata($post);
    ?>
    
    <?php if ( in_category(5) ) {
    echo '<li><a href="'.the_permalink().'"><b>'.<em>the_title()</em>.'</b></a>';
    } else {
    echo 'not category 5';
    }
    ?>
    
    <?php endforeach; ?>

    The result is like this

    //localhost/wordpress/?p=31Gamurize <ahref=""><b></b></a>

    And should be like this

    <a href="//localhost/wordpress/?p=31"><b>Gamurize</b></a>

    Why is this happening???

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter petitpoulain

    (@petitpoulain)

    Not solved yet, but this topic helped me with the permalink. Now its inside the html
    http://wordpress.org/support/topic/95091?replies=5

    I guess i need to use the custom fiel to the title too. But i read the “Using custom field” and didnt understand how to use it.
    http://codex.wordpress.org/Using_Custom_Fields

    Heres the code that worked with the permalink

    <?php
    $posts = get_posts('numberposts=10&offset=1');
    foreach($posts as $post) :
    setup_postdata($post);
    ?>
    
    <?php if ( in_category(5) ) {
    $link = get_post_custom_values('link');
    $title_url = ($link) ? $link[0] : get_permalink();
    echo '<a href="'.$title_url.'" ><b>'.$the_title.'</b></a>';
    } else {
    echo 'not category 5';
    }
    ?>
    
    <?php endforeach; ?>

    See if this happens to make any difference.

    <?php if ( in_category(5) ) { ?>
    <li><a href="<?php the_permalink(); ?>"><b> <em><?php the_title(); ?></em></b></a> <?php
    } else { ?>
    not category 5 <?php
    }
    ?>
    Thread Starter petitpoulain

    (@petitpoulain)

    thanks blepoxp.
    so simple and WORKED!

    ^^

    Great!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘In_category inside mini loop’ is closed to new replies.