Forum Replies Created

Viewing 10 replies - 1 through 10 (of 10 total)
  • I’ve been battling with this for a while, and here’s what i’ve come up with.

    <?php
    	global $post;
    	$categories = get_the_category();
    	$thiscat = $categories[0]->cat_ID;
    ?>
    <?php query_posts('showposts=5&orderby=rand&cat=' . $thiscat); ?>
    	<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    		YOUR CONTENT HERE								
    
    	<?php endwhile; else : ?>
    		Error returning query.
    	<?php endif; ?>
    <?php wp_reset_query(); ?>

    I’m not sure if that is horrendous or pretty smart, but either way it seems to work, returning all posts that are in the same category as the post being viewed – but only the FIRST category ID, ie:

    Post is in categories A, B & C. The query shows all posts that are also in A, since A was the first cat listed.

    Hope this helps.

    Dan
    http://www.wearehench.com

    Thread Starter danpacey

    (@danpacey)

    Perhaps instead of the above I can use whatever code generates the output in the image below, on the Edit Comments admin page:

    Example screenshot

    This strips http:// and www. from values stored in comment_author_url.. but I just can’t find the code for this in the core files.

    Anyone got any ideas?

    Thanks again.

    Thread Starter danpacey

    (@danpacey)

    ok, an update. I’m getting the right amout of results from this code, but not the actual values.

    <?php $querystr = "
    SELECT DISTINCT wp_postmeta.* FROM wp_postmeta
    WHERE $wpdb->postmeta.meta_key = 'area'
    
     ";
    
     $pageposts = $wpdb->get_results($querystr, OBJECT);
    
    ?>
     <?php if ($pageposts): ?>
      <?php foreach ($pageposts as $post): ?>
        <?php setup_postdata($post); ?>
    
    	<option value="<?php echo get_post_meta($post->ID, 'area', true); ?>"><?php echo get_post_meta($post->ID, 'area', true); ?></option>
    
       <?php endforeach; ?>
    <?php endif ?>1

    I have 9 “area” values in the wp_postmeta table at present, and i’m getting a list with 9 <option> tags.. but there is nothing in-between the option tags..

    putting this here in case anyone has any idea what i’m doing wrong. Many thanks again.

    Thread Starter danpacey

    (@danpacey)

    not getting anywhere fast with this, can anyone offer any advice please? thanks guys. Seems like a useful function, if it can be done!

    Thread Starter danpacey

    (@danpacey)

    ok at the moment i am trying to run this code, but it’s not generating any results.

    <?php $querystr = "
    SELECT DISTINCT wp_posts.* FROM wp_posts
    LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
    LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
    LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    WHERE $wpdb->term_taxonomy.term_id = 3,4,5,6,7,8,9
    AND $wpdb->term_taxonomy.taxonomy = 'category'
    AND $wpdb->posts.post_status = 'publish'
    AND $wpdb->postmeta.meta_key = 'area'
    ORDER BY $wpdb->postmeta.meta_value ASC
    
     ";
    
     $pageposts = $wpdb->get_results($querystr, OBJECT);
    
    ?>
     <?php if ($pageposts): ?>
      <?php foreach ($pageposts as $post): ?>
        <?php setup_postdata($post); ?>
    
    	<option value="<?php echo get_post_meta($post->ID, 'area', true); ?>"><?php echo get_post_meta($post->ID, 'area', true); ?></option>
    
    	<?php endforeach; ?>
    <?php endif ?>

    any ideas?

    will keep trying in the meantime!

    Thread Starter danpacey

    (@danpacey)

    I’ll have a look at that, thanks for your help!

    The pages i have this problem with are template files, but they aren’t pulling in anything with query_posts. I’m quite baffled by this one!

    thanks again!

    <!– double post –> πŸ™‚

    interseting topic – i think you can do a lot with wordpress, especially if you really make use of query_posts. I’m working on two sites at the moment, this one (my portfolio site) is nearly complete (will be changing/adding a few things), and i think fits the bill for being “non-bloglike”!

    http://www.danpacey.com

    i’m making use of custom fields and comments for my own ends.

    Thread Starter danpacey

    (@danpacey)

    Also: if I change the submenu code to

    ‘if(in_category(‘2′)’

    for example, the correct class is called. Therefore.. the Page MUST be in Cat 3. It’s the only explanation.

    Thread Starter danpacey

    (@danpacey)

    I am using PHP to define CSS classes, based on if statements:

    main header menu code

    <a href="?page_id=4"
    <?php if(is_page('4')){
    echo 'class="menu3_on"';
    }
    else {
    echo 'class="menu3"';
    } ?>>Group</a>
    <a href="?page_id=5"
    <?php if(is_page('5')){
    echo 'class="menu4_on"';
    }
    else {
    echo 'class="menu4"';
    } ?>>Contact</a>

    problematic submenu code:

    <li <?php if(in_category('3') ){
    echo 'class="sub1_on"';}
    else
    {echo 'class="sub1"';} ?>>
    <a href="?cat=3" (etc)

    I honestly cannot see anything in there that would cause it. I thought all pages were assigned to whatever the default Category is on creation? All of which leads me to think these Pages are assigned to Cat 3.

    thanks for your help this far!

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