Forum Replies Created

Viewing 13 replies - 211 through 223 (of 223 total)
  • Thread Starter Steven

    (@spstieng)

    Nope, this doesn’t work either….

    $table_prefix = $wpdb->prefix;
    
    $querystr = "
    			SELECT (*)
    			FROM {$table_prefix}posts, {$table_prefix}term_relationships, {$table_prefix}term_taxonomy
    			WHERE {$table_prefix}posts.ID = {$table_prefix}term_relationships.object_id
    			AND {$table_prefix}term_relationships.term_taxonomy_id = {$table_prefix}term_taxonomy.term_taxonomy_id
    			AND {$table_prefix}term_taxonomy.taxonomy = 'category'
    			AND {$table_prefix}term_taxonomy.term_id = 21
    			AND post_status = 'publish'
    			AND post_type != 'page'
    		";

    Thread Starter Steven

    (@spstieng)

    I think I’m on a wild track with a LEFT JOIN right?
    I should maybe use sub selection. Something like

    $querystr = "
    		SELECT COUNT(*)
    		FROM $wpdb->posts, $wpdb->term_taxonomy
    		WHERE posts.post_type = 'post'
    		AND posts.post_status = 'publish'
    		AND ID = term_id
    		AND term_id = 21;
    		";
    		$result = $wpdb->get_var($querystr);

    After reading about the WordPress Taxanomy, I’m a bit uncertain if I should use wp_term_relationships or wp_term_taxonomy.

    All I need is to count the number of published posts in a category. Shouldn’t bee that hard….

    The empty bar is a result of CSS classes.

    edit the styles.css if you want remove the bottom border.

    Thread Starter Steven

    (@spstieng)

    Any suggestions anyone?
    Any help is appreciated ??

    Thread Starter Steven

    (@spstieng)

    I’m continuing this post here.

    Thread Starter Steven

    (@spstieng)

    Ok, I’m almost there.
    This code ouputs the number of posts in the category.

    function get_post_count($categories) {
    	global $wpdb;
    
    	$post_count = 0;
      foreach($categories as $cat) :
    		$querystr = "
    			SELECT count
    			FROM $wpdb->term_taxonomy
    			WHERE term_id = $cat";
      	$result = $wpdb->get_var($querystr);
      	$post_count += $result;
      endforeach;
    
      return $post_count;
    }

    Now I have to figure out how to subtract the number of posts which is not published.

    I think I will needing to use a LEFT JOIN (or RIGHT JOIN).
    But I’m not good using JOIN.

    Thread Starter Steven

    (@spstieng)

    “wp_list_categories, displays a list of Categories as links”

    Any suggestions on how I can avoid listing categories?
    And just get the post count?

    Thread Starter Steven

    (@spstieng)

    Hi Velvet.
    I’m not counting the categories, but the number of posts within one or more categories.

    In the page template I have a meta_tag for which categories I would like display posts. I retrieve all posts for all categories defined in the meta_tag.

    Now I need to display how many posts that is.

    In the query_posts() have you tried using ‘order=ASC’ or ‘order=DES’?

    I use the following code:
    query_posts(“$cat&paged=$page&orderby=title&order=ASC”);

    ($cat is a concatinated string and $page is for pagiantion purpose)

    Forum: Fixing WordPress
    In reply to: Paged Comments
    Thread Starter Steven

    (@spstieng)

    Didn’t quite understand you answer hotkee.
    I am using query_posts()
    query_posts(‘showposts=3&cat=15’);

    Well, I’ve created a workaround. I’ve added a custom fild fot image title and will use this for ALT text.

    Thread Starter Steven

    (@spstieng)

    <div id="leftcol">
        <?php
          // "Featured articles" (Nyheter) module begins
          query_posts('showposts=3&cat=15'); ?>
          <h3> Nyheter  </h3>
          <?php while (have_posts()) : the_post(); ?>
          <div class="feature">
    
      <?php
    	$basePath = get_option('upload_path') . '/';
    	$permaLink = get_permalink();
    	// this grabs the image filename ffrom image gallery
    	$values = get_post_custom_values("featuredarticleimage");
    
    	// this checks to see if an image file exists
    	if(empty($values[0]))
    	{
    		//Grab url to external image
    		$values = get_post_custom_values("externalthumb");
    		$basePath = '';
    	}
    
    	// If and image has been related, it will be displayed
    	if(!empty($values[0]))
    	{
      	echo '<a href="' . $permaLink . '">';
      	echo '<img src="' . $basePath[0] . $values[0] . '" alt="artikkelbilde" />';
      	echo '</a>';
      }
      ?>
    
          <a href="<?php the_permalink() ?>" rel="bookmark" class="title">
            <?php the_title(); ?>
          </a>
          <p>
            <?php the_content_rss('Les mer','', '', 20); ?>
            <a href="<?php the_permalink() ?>">Les mer</a>.
          </p>
        </div>
        <?php endwhile; ?>
      </div>
      <!--END LEFTCOL-->

    See the line echo ‘<img src=”‘ . $basePath[0] . $values[0] . ‘” alt=”artikkelbilde” />’; ?

    I will replace ‘artikkelbilde’ with the_title() and the new code looks like this:
    echo ‘<img src=”‘ . $basePath[0] . $values[0] . ‘” alt=”‘ . the_title() . ‘” />’;

    You can see the result here.

    Notice the small linked text in front of the headline. This is the ALT text. If you look at the source code, you will see alt=””.

    Thread Starter Steven

    (@spstieng)

    That was quick ??
    I think it’s within a custom loop?

    <?php while (have_posts()) : the_post(); ?>
    (... , my code here)
    <?php endwhile; ?>

Viewing 13 replies - 211 through 223 (of 223 total)