Support » Themes and Templates » the_title(), get_the_title() both returning page rather than post values

  • Resolved wp_snowman1980


    Hi guys

    I am creating a custom theme.

    I have set WPAdmin > Settings > Reading > Front page to be “Home” (static page)

    For “Home”, I have WPAdmin > Pages > “Home” > Template set to “Front Page” which is the template name for the template I’ve created for the homepage (front_page.php).

    I have added several test posts under 2 categories : 1) smallprint 2) quote


    On front_page.php, I want to get all posts with category of “quote” and loop through them, outputting the title and content of that post.

    The code below seems to output the content of the post fine, but the title it outputs is the page title (“Home”), not the post title.

    I’ve also tried echo the_title() and using the WordPress Loop. All to no avail.

    	global $quote;
    	$firstQuote = true;
    	$quote_cat_id = get_cat_ID('quote');
    	$quotes = get_posts('category='.$quote_cat_id);
    	foreach($quotes as $quote) : setup_postdata($quote);
    	<div class="item <?php if ($firstQuote) echo "active"; ?>">
    		<p><span>“</span><?php echo get_the_content(); ?><span>”</span></p>
    		<footer><?php echo get_the_title(); ?></footer>
    	$firstQuote = false;

    This is really confusing me, could anyone point out where I’ve gone wrong? I feel I’ve tried everything I can and this is a last resort.

    Thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • By the way, I’ve also tried using the $post object:


    Both to no avail.




    Forum Moderator

    the Codex does not point this out explicitely, but you have to use:

    foreach($quotes as $post) : setup_postdata($post);

    (as in the examples in the linked Codex chapter) to get it to work.

    also, after the ‘foreach’ loop, add:

    Hi alchymyth

    Thanks for taking the time to reply.

    I can’t believe that I missed that fix, it worked!

    Some good karma is coming your way!


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘the_title(), get_the_title() both returning page rather than post values’ is closed to new replies.