• Resolved jeroslav

    (@jeroslav)


    So what I want to create is a page that will show its own “blog” (posts) that will differ from the posts on published on other pages.

    So what I was thinking to do is to create a custom page, name a template and also name the file like the custom page template. After that, create the page and give the title the same as the template name.

    After that I went on WP CODEX and copied the Page of posts code into the custom page template file (which is basically copied index.php, but little modified).

    <?php
    /*
    Template Name: Page Of Posts
    */
    
    /* This example is for a child theme of Twenty Thirteen:
    *  You'll need to adapt it the HTML structure of your own theme.
    */
    
    get_header(); ?>
    
    	<div id="primary" class="content-area">
    		<div id="content" class="site-content" role="main">
            <?php
            /* The loop: the_post retrieves the content
             * of the new Page you created to list the posts,
             * e.g., an intro describing the posts shown listed on this Page..
             */
            if ( have_posts() ) :
                while ( have_posts() ) : the_post();
    
                  // Display content of page
                  get_template_part( 'content', get_post_format() );
                  wp_reset_postdata();
    
                endwhile;
            endif;
    
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
            $args = array(
                // Change these category SLUGS to suit your use.
                'category_name' => 'music, videos',
                'paged' => $paged
            );
    
            $list_of_posts = new WP_Query( $args );
            ?>
            <?php if ( $list_of_posts->have_posts() ) : ?>
    			<?php /* The loop */ ?>
    			<?php while ( $list_of_posts->have_posts() ) : $list_of_posts->the_post(); ?>
    				<?php // Display content of posts ?>
    				<?php get_template_part( 'content', get_post_format() ); ?>
    			<?php endwhile; ?>
    
    			<?php twentythirteen_paging_nav(); ?>
    
    		<?php else : ?>
    			<?php get_template_part( 'content', 'none' ); ?>
    		<?php endif; ?>
    
    		</div><!-- #content -->
    	</div><!-- #primary -->
    
    <?php get_footer(); ?>

    I have no knowledge of PHP. Please could anyone help me, where should I put the post-item HTML and stuff. ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • where should I put the post-item HTML and stuff.

    please be more specific with what you need help.

    is it about replicating the HTML structure of your theme?

    then please post the name and download link of the theme, and ideally a link to your site, to the page which is using the page-of-posts template.

    Thread Starter jeroslav

    (@jeroslav)

    Ravinder Kumar: Thank you for the WP_query reference, it sure is a must read!

    alchymyth: Yes its about replicating my HTML structure, but with some changes in CSS.

    I am working on my own theme, and its located on localhost, so I cant post any links here.

    I managed to solve it anyway. I think there are more ways how to solve it.
    I created a new category in Administration panel for this specific page. Then I added this code

    <?php $page_query = new WP_Query('post_type=post&category_name=predpisi'); ?>
    		<?php while ($page_query->have_posts()) : $page_query->the_post(); ?>

    With category_name= /* chosen category name for that specific page */

    After that I excluded to show the posts by the same category on index.php with this:

    <?php
    if ( is_home() ) {
    query_posts( ‘cat=-32’ );
    }
    ?>

    32 is ID of the category we dont want to display on the page.
    – excludes the category.

    That is one possible way to solve this and it works fine for me. Anyway thanks for your time ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘A Page of Posts’ is closed to new replies.