WordPress.org

Ready to get started?Download WordPress

Forums

Page displays the header as a post (11 posts)

  1. vind
    Member
    Posted 1 year ago #

    I'm setting up my home page and am at the moment working out a news page that will display a set of news posts.

    While I'm not a coder and have little experience with the subject, I have thus far managed to create a static page which displays my news posts in a desired format, by using a slight modification of the template posted under "A Page of Posts" on the codex site for pages.

    The only problem is that I haven't managed to integrate it perfectly with my Twenty Twelve child theme, and the news page's headline is currently being treated as a post.

    The website in question follows here.

    Could anyone please provide me with step by step instructions for how to fix this?

    Also, while I have removed the sidebar by preventing pageofposts.php from loading it, how come the text does not fill the total page width? I guess it's more comfortable to read the way it displays now; but I'm curious about where this setting resides, though.

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    by using a slight modification of the template posted under "A Page of Posts"

    please paste the full code into a pastebin and post the link to it here; http://codex.wordpress.org/Forum_Welcome#Posting_Code

    why 'announcements' is posted first in the loop depends on the exact query you have used in the template.

    Twenty Twelve stretches the content to full width by using a css body_class .full-width which gets added via a filter function to the respective templates;
    this needs to be done in functions.php of the child theme for any new template - using the exact template's file name;

    example:

    add_filter('body_class','twentytwelvechild_body_class_adapt',20);
    function twentytwelvechild_body_class_adapt( $classes ) {
    
    	if ( is_page_template( 'pagesofposts.php' ) )
    		$classes[] = 'full-width';
    
    	return $classes;
    }
  3. vind
    Member
    Posted 1 year ago #

    Okay, so I pasted the code here.

    How do I implement the latter? I created a functions.php file under the child theme directory and pasted your code into it, but that just made it display the code ontop throughout the site.

  4. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    http://codex.wordpress.org/Child_Themes#Using_functions.php

    a new functions.php has to start with <?php in the first line

    (and nothing whatsoever before that code)

    this part is creating the output of the actual page, i.e. the 'announcement' title output:

    /* the_post will retrieve the content of the new page you
      *  create to list the posts, e.g. as an intro to describe
      *  which posts are shown.
      */
      the_post(); 
    
      // Display content of page
      get_template_part( 'content', get_post_format() );
      wp_reset_postdata();

    remove that section.

    also consider to add wp_reset_postdata(); after the endwhile;.

  5. vind
    Member
    Posted 1 year ago #

    Hm. But that removes the page headline completely. How can I make it display regularly like on the other pages?

  6. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    But that removes the page headline completely. How can I make it display regularly like on the other pages?

    you could replace this:
    // Display content of page
      get_template_part( 'content', get_post_format() );

    with:

    // Display content of page
    	<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    		<header class="entry-header">
    			<h1 class="entry-title"><?php the_title(); ?></h1>
    		</header>
    </article>
  7. vind
    Member
    Posted 1 year ago #

    The page goes blank when I do that.

  8. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    I forgot to include the php tags;

    // Display content of page
    ?>
    	<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    		<header class="entry-header">
    			<h1 class="entry-title"><?php the_title(); ?></h1>
    		</header>
    </article>
    <?php
  9. vind
    Member
    Posted 1 year ago #

    It made all the posts turn into body headlines with no content. *shrugs*

  10. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    that section appears twice - I was referring to the first one in line 22/23 of your pastebin code.

  11. vind
    Member
    Posted 1 year ago #

    Err. Turns out I had somehow deleted that section from my .php file.

    Anyhow, I got it working at last.

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic