if ( $my_query->have_posts() && ( ( $my_query->post_count ) >= 3 ) )
Here’s a link to the code:
Thanks so much.
]]><?php
$key = 'member-name';
$tag = get_post_meta($post->ID, $key, true);
$args=array(
'numberposts' =>5,
'tag' => $tag,
'orderby' =>'post_date',
'order' => 'DESC',
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo 'Recent News:';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php
the_title_attribute(); ?>"><?php the_title(); ?
></a>
</li>
<?php
endwhile;
} //if ($my_query)
wp_reset_query(); // Restore global post data stomped by the_post().
?>
But now I want to add an RSS feed image next to Recent News, which isn’t a problem. It’s when I want to link that image to the page’s custom field that gets to be a problem. I have tried a number of combinations but this seemed to make the most sense to what I’m trying to do…but it doesn’t work.
<?php
$key = 'member-name';
$tag = get_post_meta($post->ID, $key, true);
$args=array(
'numberposts' =>5,
'tag' => $tag,
'orderby' =>'post_date',
'order' => 'DESC',
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo '<a href="../tag/<?php $key= "member-name"; echo get_post_meta($post_ID,$key,true); ?>/feed">
<img src="../wp-content/uploads/RSSfeed24transparent.png" /></a> Recent News:';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php
the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php
endwhile;
} //if ($my_query)
wp_reset_query(); // Restore global post data stomped by the_post().
?>
The problem arises with this part of the code:
<a href="../tag/<?php $key= "member-name"; echo get_post_meta($post_ID,$key,true); ?>/feed">
I have plugged in one of the values in the place of the php script, and I got what I was looking for. So I’m just wondering if I’m getting too deep in the code and need extra () or {} or something like that to help separate it?
I need to show a list of post titles that match all the categories of the current post. This is what I’ve got so far, but get_the_category( $id ) gets the ID of the first category, not all categories, thus the query returns all posts that match the first category. I need it to return only posts that match all categories.
<?php
$match1 = get_post_meta($postid, 'classLevel', true);
$match2 = get_the_category( $id );
if($match1 = 'Beginner') {
$args = array(
'post_type' => 'class',
'meta_key' => 'classLevel',
'meta_value' => 'Intermediate',
'category__in' => $cat_id,
'posts_per_page' => 20, //limit the post numbers,or use -1 for all
'post__not_in' => array($post->ID), //exclude current post
);
} else {
$args = array(
'post_type' => 'class',
'meta_key' => 'classLevel',
'meta_value' => 'Advanced',
'category__in' => $cat_id,
'posts_per_page' => 20, //limit the post numbers,or use -1 for all
'post__not_in' => array($post->ID), //exclude current post
);
}
$my_query = new WP_Query($args); ?><?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php if (function_exists('get_cat_icon'))
get_cat_icon('fit_width=12&fit_height=12&link=false&small=true&class=caticon'); ?><?php the_title();?></a></li>
<?php endwhile;?>
<?php wp_reset_query(); ?>
<?php echo get_the_category( $id ) ?> returns “array”–not an array, the word “array.”
How do I make the query return only those posts that match all the categories of the current post?
Thanks in advance for the help.
]]>This code works great for the first part, getting the list of posts:
<?php $args=array('category_name' => 'mycategoryname' , 'post_type' => 'mycustomposttypename',);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php endwhile; }
wp_reset_query(); ?>
Now, if I could refine the query further, I’m trying to find the permalink to a category with a name identical to what is shown in the_title. I thought this might help:
<?php
$pageslug = $post->post_name; // name of the page (slug)
$catslug = get_category_by_slug($pageslug); // get category of the same slug
$catid = $catslug->term_id; // get id of this category
$query= 'cat=' . $catid. '';
query_posts($query); // run the query
?>
But combining these two seems to be beyond me as I keep breaking everything.
If this is the wrong approach feel free to suggest alternatives.
]]>I’m using WordPress as a CMS and what I’m trying to do is create a site-map type footer that’s going to list all pages within each category. An example of this would be what’s going on in the footer of this website – mesa.cityofgrace.com.
From using the “Debug Queries” plug-in from Frank Bültge, I’ve found out that I’m using about 14 queries per page–this is with 3 plug-ins installed.
So what I’m doing for my site-map like footer is creating custom loops for each category, listing out all of the pages under them (like in the example Web site above). I have 5 categories in my WordPress CMS Web site with about 5-7 pages within each section/category. When I do this, the number of queries jumps to about 32 queries per page. The code I’m using us pasted below.
I feel like I’m doing these loops incorrectly and generating unnecessary queries. Can anyone help me with the proper way to code my multiple loops?
I’m reusing the following code 5 times in the footer for my “site map” and it’s generating 18 more queries.
<ul class="footer-lists">
<li><a href="#" title="" class="bold">About Me</a></li>
<?php
$categories = array(7);
if ($categories) {
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
$args=array(
'category__in' => $categories,
'showposts'=>12,
'caller_get_posts'=>1
);
$my_query = new wp_query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_title(); ?>
</a></li>
<?php
}
echo '</ul>';
}
}
]]>Using a this query:
<h3>client news</h3>
<?php $my_query = new WP_Query('cat=4&showposts=3'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><?php the_excerpt(); ?></p>
<p class="readmore"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">read more ></a></p>
<?php endwhile; ?>
I’d like to have the <h3> show the category title instead of being typed in the template, so if the category is empty the title doesn’t show. But if the category title tag is added below the query, it shows above each post. Adding it between the query and the while tags shows “uncategorized”.
How can I get the category title to display only at the top of a list of posts?
]]>