Support » Fixing WordPress » i want to get posts based on page name

  • Resolved sheriffderek


    so on a record label website, there are pages of artists. my goal was to use the same template for all. below the bio section, i wanted to get posts for that artist. the posts are tagged “news” but i only want news from the artist. without making individual themes – i thought i would do this by getting the posts by page title – since the page title is also the artists name.

    so – get post of the category that is the same as the page-title.

    first attempt was to insert echo like this

    <?php query_posts('category_name=posts&showposts=0') ?>

    which pulls all “posts”
    then figured i could add an echo in there in place –

    <?php query_posts('category_name=<?php echo get_the_title($ID); ?> &showposts=0') ?>

    but no go-

    any ideas ? i think i’m going about this all wrong – but i can’t wrap my head around it. ? ? ? i want my client to be able to create new pages without my help… and this would solve that issue.


Viewing 7 replies - 1 through 7 (of 7 total)
  • So you have a page like:

    “Sheriff Derek”

    and then you have posts that have been placed in a category called “sheriff derek”.

    Try this code:

    $artistcat = get_the_title();
    query_posts('category_name=$artistcat'); ?>
    <?php query_posts('category_name=' . strtolower(the_title('','',false)) . '&showposts=0'); ?>
    <?php while ( have_posts() ) : the_post(); ?>
    <?php the_content(); ?>
    <?php endwhile; ?>
    <?php wp_reset_query(); ?>

    thank you 2 for your replies. i still haven’t worked it out… but i did start wondering about re-setting my queries. so i did… and that cleared up some other issues… so then i went back and tried your examples again… but i’ve had no luck.

    here are some up to date examples:

    <div class="entry">
    			<img alt="release image" src="<?php echo get ('artists_image') ?>"> <br />
    			<div class="blog-text">
    				<h2 class="header"><?php echo get ('artists_name') ?> :</h2>
    			<div class="blog-text">
    				<?php echo get ('artists_bio') ?>
    		</div> <!--end entry-->

    no problem getting the info here… out of the loop.

    <?php query_posts( array(
    			'artist' => 'san-gabriel',
    			'showposts' => 3
    			) ); ?>

    getting shows:

    <?php query_posts( array(
    			'cat' => 'shows',
    			"order" => 'desc',
    			'orderby' => 'meta_value',
    			'meta_key' => 'show_info_date',
    			'artist' => 'san-gabriel'
    			) ); ?>

    getting relative posts:

    now “san-gabriel” is the artist name in this case (both of these queries are right before their loops. and the loops are reset.)

    both of the previous responses make total sense to me logically… but they break the page… is there anything in these examples that might show what exactly i am not understanding ? thank you so much for even taking the time to read this. -dw

    <?php wp_title("",true); ?> <br />
    this returns San Gabriel
    <?php echo get ('artists_name') ?>
    this also returns San Gabriel

    <?php query_posts( array(
    	'artist' => 'san-gabriel',
    	'showposts' => 3
    	) ); ?>

    my aim is to replace san-gabriel here – with one of the above…

    accidentally got so worked up i started a second post without remembering the first !!! sorry !!!

    anyways – post got solved !!! thanks to everyone who chimed it !!!

    here is the other thread… i am terrible with using this text box…

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘i want to get posts based on page name’ is closed to new replies.