Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom theme and have built a blog page where I'd like to utilize "the loop", but get_content() is not working. Instead of displaying page content, it displays code from a template. I don't understand why this doesn't function properly, because get_posts(), the_time(), and the_title() all work fine... here's what my code looks like:

   <?php get_header(); ?>


        <div id="bottom-wrapper-page">
        <div class="breadcrumbs">
        <?php if(function_exists('bcn_display'))
            {
                bcn_display();
             }?>
         </div><!--.breadcrumbs-->
         <div id="delimeter"></div>

        <!--[if IE ]><div id="ie"><![endif]-->
        <!--[if !IE]>--><div id="post"><!--<![endif]-->            

            <?php if( is_page('blog') ) { 
             $debut = 0; //The first article to be displayed

              while(have_posts()) : the_post(); ?>
               <h2><?php the_title(); ?></h2>
               <div id="bp">
             <?php
               $myposts = get_posts('numberposts=-1&offset=$debut');
             foreach($myposts as $post) :
             ?>
              <div class="bl_date"><?php the_time('d/m/y'); ?>
              </div><!--.bl_date-->
              <div class="bl_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div><!--.bl_title-->
               <div class="bl_teaser">
              <?php the_content(); ?>
                </div><!--.bl_teaser-->  
              <?php endforeach; ?>
              </div><!--#bp-->
             <?php endwhile; ?>
            <?php } else{ ?>

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

                <?php get_template_part( 'content', 'page' ); ?>


                <?php endwhile; // end of the loop. ?>

            <?php } ?>
        </div><!-- #post (or #ie) -->  

        <?php get_sidebar(); ?>

        <?php get_footer(); ?>  

        </div><!-- #bottom-wrapper-page -->

And my output:

03/05/12
 Cool Post 1
 /*
  Template Name: All posts
  */
   ?>
    $debut = 0; //The first article to be displayed
    ?>
    $myposts = get_posts('numberposts=-1&offset=$debut');
     foreach($myposts as $post) :
      ?>
    : 03/05/12
   Test Post
   /*
    Template Name: All posts
    */
     ?>
    $debut = 0; //The first article to be displayed
     ?>
    $myposts = get_posts('numberposts=-1&offset=$debut');
    foreach($myposts as $post) :
    ?>
     : 19/04/12
     Hello world!
    /*
    Template Name: All posts
    */
   ?>
   $debut = 0; //The first article to be displayed
    ?>
   $myposts = get_posts('numberposts=-1&offset=$debut');
     foreach($myposts as $post) :
    ?>
     :

Whatever it is, it's messing with my css as well. I noticed he /* Template Name: All posts */, but I don't have a template (to my knowledge) named all posts, so I don't know where this code came from. If anyone could please lend a hand, I'd greatly appreciate it

share|improve this question

closed as too localized by EAMann May 4 '12 at 22:05

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Is this the actual output of the page? It looks like you have a bunch of broken/unopened PHP tags there. Also, I don't see you calling the_content() in your first code block at all ... –  EAMann May 4 '12 at 20:54
    
thanks for bringing that to my attention EAMann. I forgot to add the_content() call in this question. But that is the actual output of the page even with the appropriate call. I've edited my op to reflect the call to the_content(). –  Kyle May 4 '12 at 21:06
    
Can You edit the question and post all the code, you are not calling the_content() and from the output is seems like there is some echo and some php tags not closed, the <?php the_time('d/m/y'); ?> mentioned by george will not cause such output –  user983248 May 4 '12 at 21:07
    
Can you post the contents of the entire file that includes this code? From the looks of things, the foreach is executing properly, but then it's displaying another foreach inline ... There might be some strange echoing going on, but without seeing what comes before this code block or knowing how the block is included by WP, I can't be sure. –  EAMann May 4 '12 at 21:11
1  
From the looks of things, this is something that needs some hand's on support. I recommend you take the conversation to the official support forums and I'll close the question here as "Too localized." Not a bad thing, just a way of pointing out that this kind of question needs to be moved to a better venue. –  EAMann May 4 '12 at 22:05

1 Answer 1

I think I see what's happening here. You need to add a ; after the time -

<?php the_time('d/m/y'); ?>

Even though I'm a bit surprised you got an output at all.

share|improve this answer
    
I see what you mean george, and thanks for the answer. Unfortunately, it did not solve my issue. Do you have any other suggestions? –  Kyle May 4 '12 at 21:02
    
The problem is that the code you pasted above don't relate to the actual output so it's just guessing. Are you child theming this? –  george.n May 4 '12 at 21:06
    
No, I'm not child theming. How is it that the date and title's display though? –  Kyle May 4 '12 at 21:08
    
the date and title are displaying because the php tags are properly closed... but somewhere in your code there's either an unclosed tag or return or even echo .... can you edit your question and post all the code like user983248 suggested? –  george.n May 4 '12 at 21:12
    
Sure thing george.n, I've just done so. –  Kyle May 4 '12 at 21:14

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