WordPress.org

Ready to get started?Download WordPress

Forums

Displaying Category and Post Name trouble (3 posts)

  1. mikedistras
    Member
    Posted 2 years ago #

    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,

  2. s_ha_dum
    Member
    Posted 2 years ago #

    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'); ?>

  3. mikedistras
    Member
    Posted 2 years ago #

    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!!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.