WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Loop isnt working? (9 posts)

  1. NazarA
    Member
    Posted 1 year ago #

    Im completely confused and I dont know what to do!

    I am developing a static page for a blog of mine. Here's the html code

    <?php /* Template Name: Blog */ ?>
    
    <?php get_header(); ?>
    <div class="blog-container ">
    	<div class="mainblog">
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
            <div class="post">
             <h1 class="header"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
               		 <h2 class="infoheader"><?php the_date(); ?> | <?php the_time('H:i') ?> | <?php the_category(); ?>  </h2>
                        <div class="thumbnail"><?php the_post_thumbnail(); ?></div>
     	    				<?php the_excerpt(); ?>
        	</div> <!--post-->
       <?php endwhile; endif; ?>
    </div> <!--mainblog-->
    <?php get_sidebar(); ?>
    </div> <!--blog-container-->
    
    <div><?php get_footer(); ?></div>

    All i get is "Protected:blog" and "October 15, 2012 | 10:06 |" underneath it. I have made 2 quick posts which have dummy text and a featured image. (Which is clickable in the sidebar)

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

    is the 'blog' page set as 'protected' ?

    for any blog posts to show, you need to add a query before the loop;

    http://codex.wordpress.org/Function_Reference/query_posts

    for ideas, also see http://codex.wordpress.org/Pages#A_Page_of_Posts

  3. NazarA
    Member
    Posted 1 year ago #

    For now the blog is protected.

    It works (yay!) however now in my <title> all i get is " | Blue Harlequin" (site is http://www.blueharlequin.com), Im not getting this issue anywhere else!

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

    what is the code for the meta title tag <title>, in header.php?

  5. NazarA
    Member
    Posted 1 year ago #

    <title><?php bloginfo('name'); ?><?php wp_title(); ?></title>

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

    where did you add the query?
    can you post the full code of the latest version of the page template?

    if using 'query_posts()' is interfering with the meta title, you might need to use a secondary loop for your blog posts;

    example:

    <?php /* Template Name: Blog */ ?>
    
    <?php get_header(); ?>
    <div class="blog-container ">
    	<div class="mainblog">
       <?php $blogs = new WP_Query( array( 'post_type' => 'post', 'paged' => get_query_var('paged') ); ?>
       <?php if ($blogs->have_posts()) : while ($blogs->have_posts()) : $blogs->the_post(); ?>
    
            <div class="post">
             <h1 class="header"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
               		 <h2 class="infoheader"><?php the_date(); ?> | <?php the_time('H:i') ?> | <?php the_category(); ?>  </h2>
                        <div class="thumbnail"><?php the_post_thumbnail(); ?></div>
     	    				<?php the_excerpt(); ?>
        	</div> <!--post-->
       <?php endwhile; endif; wp_reset_postdata(); ?>
    </div> <!--mainblog-->
    <?php get_sidebar(); ?>
    </div> <!--blog-container-->
    
    <div><?php get_footer(); ?></div>

    http://codex.wordpress.org/Class_Reference/WP_Query

  7. NazarA
    Member
    Posted 1 year ago #

    <?php /* Template Name: Blog */ ?>
    
    <?php get_header(); ?>
        <h1>Blog</h1>
    
    <div class="blog-container ">
    	<div class="mainblog">
    <?php query_posts( 'posts_per_page=5' ); ?>
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
            <div class="post">
             <h1 class="header"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
               		 <h2 class="infoheader"><?php the_date(); ?> | <?php the_time('H:i') ?> | <?php the_category(); ?>  </h2>
                        <div class="thumbnail"><?php the_post_thumbnail(); ?></div>
     	    				<div class="the_excerpt"><?php the_excerpt(); ?></div>
        	</div> <!--post-->
       <?php endwhile; endif; ?>
    </div> <!--mainblog-->
    <?php get_sidebar(); ?>
    </div> <!--blog-container-->
    
    <div><?php get_footer(); ?></div>

    This is the only issue im currently having! Other than that this'll be all resolved :)

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

    I can't see any reason why the query would stop the page title from showing in the meta title tag (unless you are using a seo plugin?);

    you could try to add 'wp_reset_query();' at the end of this line:

    <?php endwhile; endif; ?>

    i.e.

    <?php endwhile; endif; wp_reset_query(); ?>
  9. NazarA
    Member
    Posted 1 year ago #

    Actually I am using an seo pack (all-in-one SEO to be exact)

    Just tried your code and it works! Thank you! :)

Topic Closed

This topic has been closed to new replies.

About this Topic