post_title / the_title help needed

The below code displays my selected page, its content and shortocde correctly. The page is selected from a theme options panel in the WP Admin.

I am struggling to echo the title. At the moment it’s echoing all page titles. Any help much apreciated!

Read More
<?php
     $blockwho = get_option('good_blockwho');
     $homeblockwho = get_pages ('post_name='.$blockwho); ?>


<?php foreach ($homeblockwho as $hbw) {   
     $content = $hbw->post_content;
     $title = $hbw->post_title;
     apply_filters('the_content', $content);

     echo "<h2><span>".$title."</span></h2>";
     echo "".do_shortcode($content)."";
}?>

Thanks again!

Related posts

Leave a Reply

5 comments

  1. to echo the title of a singular wordpress page, you do this wordpress function

    <?php the_title() ?>
    

    you can also surround it with some html for css formatting like follows->

    <h2><?php the_title() ?></h2>
    

    good luck

  2. according to the Codex : http://codex.wordpress.org/Function_Reference/get_pages

    “post_name” is not an argument for get_pages, it’s a possible value for “sort_column”.

    Try the following:

    <?php
    global $post;
    $blockwho = get_option('good_blockwho');
    $page = get_page_by_title($blockwho);
    
    $myposts = get_posts('post_type=page&p='$page->ID);
    foreach($myposts as $post) :
    setup_postdata($post);
    ?>
    
        <?php the_title(); ?>
    
    <?php endforeach; ?>
    
  3. <?php
         $blockwho = get_option('good_blockwho');
         $homeblockwho = get_pages ('post_name='.$blockwho); ?>
    
    
    <?php foreach ($homeblockwho as $hbw) {   
         $content = $hbw->post_content;
         $title = $hbw->post_title;
         apply_filters('the_content', $content);
    
         echo "<h2><span>".$homeblockwho ->post_title."</span></h2>";
         echo "".do_shortcode($content)."";
    }?>
    
  4. If you like to echo just the one page, this should do the trick:

    <?php
    $blockwho = get_option('good_blockwho');
    $page = get_post($blockwho);
    
    $content = $page->post_content;
    apply_filters('the_content', $content);
    
    echo "<h2><span>".$page->post_title."</span></h2>";
    echo "".do_shortcode($content)."";
    
  5. Firstly I would recommend storing the actual page/post ID in the options table rather than the name of it, you can still display page titles to the user, just have a dropdown box with the option values as IDs

    Have you checked $page->ID from j-man86’s answer is actually returning the correct ID?

    Assuming the stored option is a page ID rather than a page title, the following would work

    $page = get_page(get_option('good_blockwho'));
    $title = $page->post_title;
    $content = apply_filters('the_content', $page->post_content);