1

For my website, I am using a static home page page Home (template front-page.php) and for posts- page News (template home.php)

I need to show all the post titles and exceprts on that page News (templ. home.php), but also show the original title and the_content from that page News itself.

This code below while statement shows all the posts, which is good, but the top the_title also shows the title from the first post, not from the News page itself.

How to achieve what I need?

<?php get_header(); ?>

    <?php
    the_title();
          the_content();
    ?>

<?php if(have_posts()) while(have_posts()) : the_post(); ?>

        <?php
        the_title();
        ?>

        <?php
        the_content();
        ?>

    <?php
    endwhile;
    ?>  

<?php get_footer(); ?>
3
  • Please rephrase your problem. I am unable to get anything :/
    – Sisir
    Commented Jun 17, 2014 at 12:16
  • tried a bit clarify :)
    – jam
    Commented Jun 17, 2014 at 12:24
  • Check out the code in EDIT 2 of my answer here. Seems that is what you are looking for. Just modify as needed Commented Jun 17, 2014 at 12:42

3 Answers 3

3

get_queried_object() stores the original object that was found as a match for the permalink.

It's the WP_Post object of your News Page

$news_page = get_queried_object();
echo $news_page->post_title;
0
  <?php get_header(); ?>

    <?php
    the_title();
          the_content();
    ?>

Replace with

<?php get_header(); ?>

<?php
  $page_id = $wp_query->query_vars['page_id'];

  echo get_the_title($page_id);
  echo apply_filters('the_content', get_the_content($page_id));
?>
3
  • echo $page_id returns 0 :/
    – jam
    Commented Jun 17, 2014 at 13:03
  • $page_object = get_queried_object(); $page_id = get_queried_object_id(); Did the trick
    – jam
    Commented Jun 17, 2014 at 13:14
  • echo $page_id returns 0 :/ fixed Commented Jun 17, 2014 at 14:11
0

This is what I did on a recent site:

$blog_page_object      = get_queried_object();
$blog_page_title       = $blog_page_object -> post_title;
$blog_page_description = apply_filters('the_content', $blog_page_object -> post_content );

?>

<h1><?php echo( $blog_page_title ) ?></h1>
<?php echo( $blog_page_description ) ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.