Hello, which theme/childtheme are you using?
what it seems, there is a normal default loop, so it could work the way you intend either if you set this to be a category template, or if you’re making a page template, you have to set a custom loop to pull posts from one specific category.
By now I can suggest to take a look at
The Loop
The Loop in Action
and WP_query
tell if you still are in doubt,
hope this can help you
Thank you parcodeisuoni,
This is from the Vulcan theme. I’ve copied page.php, edited it as you see above, and saved it as our-clients.php to run only this one page of the site. So yes it is intended to be a custom loop to pull posts from one specific category.
Ok, so it’s what you can find in
codex.wordpress.org/Class_Reference/WP_Query
at the beginning of the page there are a couple of examples on how to set custom loops.
you’ll see that the loops call $args to set the behaviours of the loop.
you can find what you’re searching a little down on the page, at
Category Parameters
Show posts associated with certain categories.
cat (int) – use category id.
category_name (string) – use category slug (NOT name).
category__and (array) – use category id.
category__in (array) – use category id.
category__not_in (array) – use category id.
anyway as a quick reference I found useful this suggestion from WP:
Comprehensive Argument Reference by Mark Luetke
about metadata, you’re actually making it good, but inside the loop you don’t need to reference the global $post…
this lines of code you wrote
<?php $short_desc = get_post_meta($post->ID, '_short_desc', true ); ?>
<p><?php echo $short_desc;?></p>
is enough to show the metadata for the post you’re in when making your custom loop.
glad if it helps
Marcello
Sorry, I made a mistake about metadata, I just see it…
..is BEFORE the loop, so referencing the $post global is needed.
for the loop part, just add to `<?php
/*
Template Name: Our Clients
*/
get_header();?>
<!– BEGIN OF PAGE TITLE –>
<?php if (have_posts()) : ?>`
this lines:
<?php
/*
Template Name: Our Clients
*/
get_header();?>
<!-- BEGIN OF PAGE TITLE -->
<?php $clients_query = new WP_Query( 'category_name=YOURCATEGORY' );
if ($clients_query->have_posts()) : ?>
changing YOURCATEGORY with the slug you have for clients…
and then for the loop, using <?php while ($clients_query->have_posts()) : $clients_query->the_post(); ?>
sorry again, hope helps
Thank you!!!
Your information helped me a lot.
Here’s the revised (now fully functional) code. Maybe comparing this with my initial code will help others in similar situations.
<?php
/*
Template Name: Our Clients
*/
get_header();?>
<!-- BEGIN OF PAGE TITLE -->
<?php if (have_posts()) : ?>
<div id="page-title">
<div id="page-title-inner">
<div class="title">
<h1><?php the_title();?></h1>
</div>
<div class="dot-separator-title"></div>
<div class="description">
<!--[if IE]>
<style type="text/css">
.description {margin-top:30px;}
</style>
<![endif]-->
<?php global $post;?>
<?php $short_desc = get_post_meta($post->ID, '_short_desc', true ); ?>
<p><?php echo $short_desc;?></p>
</div>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
<!-- END OF PAGE TITLE -->
<div id="content">
<div id="content-left">
<div class="maincontent">
<?php
// The Query
$query = new WP_Query( array(
'category_name' => 'client',
'meta_key' => 'order',
'orderby' => 'meta_value',
'order' => 'ASC'
));
// The Loop
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();?>
<div class="blog-posted">
<div class="image-left">
<?php the_post_thumbnail( 'thumbnail' ); ?>
</div>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div>
</div>
<?php }
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
?>
<?php else: ?>
<p>Sorry, the client posts cannot be located</p>
<?php endif; ?>
</div>
</div>
<?php //endif;?>
<?php get_sidebar();?>
</div>
<!-- END OF CONTENT -->
<?php get_footer();?>
I’m glad I could help you.
If you think, you may mark this topic as resolved, it can help others to see they can find some sort of solutions here…
have a good coding time 😉