• I’m working on a website for a client, and I can’t get the posts to show up. The rest of the site is working well, but the Blog page is not.

    I’m using the Underscores Starter Theme with WordPress 3.9.1.

    The code for the Blog page is as follows:

    <?php
    /*
    Template Name: newsArchiveTemplate
    */
    
    /**
     * Beekman custom page template file.
     *
     * This is the custom page template file, called newsArchiveTemplate.
     * Beekman will be able to select this file from the Add Page drop down menu.
     */
    
    get_header(); ?>
    <?php include("leftSidebar.php"); ?>
    <?php get_sidebar(); ?>
    	<div id="primary" class="content-area" style="width:300px;  position:relative; left:300px; top:-1380px; margin-left:20px; float:left;">
    		<main id="main" class="site-main" role="main">
    
    			<?php /* Start the Loop */ ?>
    			<?php while ( have_posts() ) : the_post(); ?>
    
    				<?php
    					/* Include the Post-Format-specific template for the content.
    					 * If you want to override this in a child theme, then include a file
    					 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
    					 */
    					get_template_part( 'content', get_post_format() );
    				?>
    
    			<?php endwhile; ?>
    
    			<?php beekmantheme_paging_nav(); ?>
    
    		</main><!-- #main -->
    	</div><!-- #primary -->
    
    <!--<?php get_sidebar(); ?>-->
    
    <?php get_footer(); ?>

    I’ve been doing a lot of moving around of code, and may very well have deleted an important line.

Viewing 6 replies - 1 through 6 (of 6 total)
  • you need to add a custom query to get a list of posts shown on a page teplate;

    review for example: https://codex.www.ads-software.com/Page_Templates#A_Page_of_Posts

    Thread Starter alexWP333

    (@alexwp333)

    Thanks for the link. Based on the info on the link I revised the code for my page template to read as shown below, but when I go the site page I get a message that says:
    “Nothing Found. It seems we can’t find what you’re looking for. Perhaps searching can help.”
    Is there something missing from my new page teamplate file?

    <?php
    /*
    Template Name: newsArchiveTemplate
    */
    
    /**
     * Beekman custom page template file.
     *
     * This is the custom page template file, called newsArchiveTemplate.
     * Beekman will be able to select this file from the Add Page drop down menu.
     */
    
    get_header(); ?>
    <?php include("leftSidebar.php"); ?>
    <?php get_sidebar(); ?>
    	<div id="primary" class="content-area" style="width:300px;  position:relative; left:300px; top:-1380px; margin-left:20px; float:left;">
    		<main id="main" class="site-main" 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 beekmantheme_paging_nav(); ?>
    
    		<?php else : ?>
    			<?php get_template_part( 'content', 'none' ); ?>
    		<?php endif; ?>
    
    		</div><!-- #content -->
    	</div><!-- #primary -->
    
    <!--<?php get_sidebar(); ?>-->
    
    <?php get_footer(); ?>

    try to change:

    'category_name' => 'music, videos',

    to (untested):

    'category_name' => array('music', 'videos'),

    https://codex.www.ads-software.com/Class_Reference/WP_Query#Category_Parameters

    or use category IDs with 'category__in'

    Thread Starter alexWP333

    (@alexwp333)

    Thanks for the help. I can now see the full posts, but am also getting a warning message at the top of the blog page that says: “Warning: urlencode() expects parameter 1 to be string, array given in /home/bfd/public_html/beekman/wp-includes/formatting.php on line 3690”

    Here’s the latest code on my template file:

    <?php
    /*
    Template Name: newsArchiveTemplate
    */
    
    /**
     * Beekman custom page template file.
     *
     * This is the custom page template file, called newsArchiveTemplate.
     * Beekman will be able to select this file from the Add Page drop down menu.
     */
    
    get_header(); ?>
    <?php include("leftSidebar.php"); ?>
    <?php get_sidebar(); ?>
    	<div id="primary" class="content-area" style="width:300px;  position:relative; left:300px; top:-1380px; margin-left:20px; float:left;">
    		<main id="main" class="site-main" 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' => array('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 beekmantheme_paging_nav(); ?>
    
    		<?php else : ?>
    			<?php get_template_part( 'content', 'none' ); ?>
    		<?php endif; ?>
    
    		</div><!-- #content -->
    	</div><!-- #primary -->
    
    <!--<?php get_sidebar(); ?>-->
    
    <?php get_footer(); ?>

    Thread Starter alexWP333

    (@alexwp333)

    I opened the formatting.php file that’s referenced in the warning message above, and I’m seeing the following function, called wp_basename:

    /**
     * i18n friendly version of basename()
     *
     * @since 3.1.0
     *
     * @param string $path A path.
     * @param string $suffix If the filename ends in suffix this will also be cut off.
     * @return string
     */
    function wp_basename( $path, $suffix = '' ) {
    	return urldecode( basename( str_replace( array( '%2F', '%5C' ), '/', urlencode( $path ) ), $suffix ) );
    }

    It looks like parameter 1 of urlencode() is currently
    basename( str_replace( array( '%2F', '%5C' ), '/'

    I’m wondering what would need to be done here to make this a string, as expected.

    Any advice would be appreciated.

    Thread Starter alexWP333

    (@alexwp333)

    Just noticed that line 3690 of formatting.php file actually says “urldecode” instead of the “urlencode” that’s indicated in the warning message.

    I’m lost.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Problem displaying Posts on Blog Page’ is closed to new replies.