Support » Fixing WordPress » Displaying Category and Post Name trouble

  • Hi,

    I currently have an issue which seemed pretty straight forward, but then realising I cant use a portion of PHP within PHP seemed to knock things back a little.

    Im trying to edit the single.php file, to display posts from a sub-category that relevant to that particular post.

    The current code is:

    <?php query_posts('category_name=photos<?php the_title(); ?>&showposts=-1'); ?>
    
    <?php while (have_posts()) : the_post(); ?>
    
    <a href="<?php the_permalink() ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail(  ); } ?>
    </a>
    
    <?php endwhile;?>

    The plan being that there would be a sub-category with the same name as the post title.

    I know I could just put in the name of the sub-category directly into the query, however this has to be dynamic, so that when a new Post is added, it will display everything in the sub-category with the same name as it.

    I hope that makes sense, so any help is appreciated on doing this.

    Thanks,

Viewing 2 replies - 1 through 2 (of 2 total)
  • You don’t want nested php tags. Also, the_title() by default will echo the title. You don’t want that. Try using it like this: the_title('','',false). In other words, this

    <?php query_posts('category_name=photos<?php the_title(); ?>&showposts=-1'); ?>

    should be this

    <?php query_posts('category_name=photos'.the_title('','',false).'&showposts=-1'); ?>

    Thank you! Worked pretty much like a charm!! I knew I couldnt do nested PHP tags, but i didnt know the alternative, so thank you!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Displaying Category and Post Name trouble’ is closed to new replies.