Dz.slick
Dz.slick

Reputation: 445

Category title display issue in Wordpress

I have the code below for a category in WordPress. It displays the name of the category when I want it to be displaying the title of the post. How do I get it to display the title of the post proper.

<? query_posts('category_name=implants');
?>
<h3><?php single_cat_title(); ?></h3>
<?php if (have_posts()) : while (have_posts()) : 

the_post(); ?>
<?php the_content( __('Read the 

rest of this page »', 'template')); ?>
<?php endwhile; endif; ?></p>

Upvotes: 0

Views: 194

Answers (1)

maiorano84
maiorano84

Reputation: 11951

  1. Do not use query_posts unless your intention is to modify the default Wordpress Loop. Use WP_Query instead for standard Wordpress queries.
  2. Look at your code. You're calling single_cat_title(). It means exactly what it looks like: You're pulling the title of the queried category. You want to call the_title() to grab the post title.
  3. Not as important as the above, but your opening tag is <? rather than <?php. You should make it a habit of specifying your server-side language to avoid potential future problems, even though it might not be initially apparent.

Here's what your revised loop should look like:

<?php
$query = new WP_Query('category_name=implants');
if($query->have_posts()) : while($query->have_posts()) : $query->the_post();
?>
<h3><?php the_title(); ?></h3>
<?php
the_content( __('Read the rest of this page »', 'template'));
endwhile; endif;
wp_reset_postdata();
?>

Upvotes: 2

Related Questions