• I’m kinda at a loss on this one. None of my header link URLs are correct because my “the_permalink()” statement in the code below is returning an empty string (this is inside header.php)…

    Any ideas what might be the cause?

    <div class="myheader"><div class="myTitle"><a href="/"><?php bloginfo('name'); ?></a></div><div class="myTagline"><?php bloginfo('description'); ?></div><div class="myMenu top"><ul> <?php
    			global $post;
    			$cat=get_cat_ID('my-menu');
    			if($cat > 1)
    				{$myposts = get_posts('numberposts=5&category='.$cat);}
    			else
    				{$myposts = get_posts('numberposts=10');}
    			foreach($myposts as $post) :
    			?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li><?php endforeach; ?></ul></div></div>
Viewing 1 replies (of 1 total)
  • You need to run setup_postdata($post) just after the ‘foreach($myposts as $post) :‘ or setup your loop like this one from the Codex:

    <?php $my_query = new WP_Query('category_name=special_cat&posts_per_page=10'); ?>
    
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
      <!-- Do special_cat stuff... -->
    <?php endwhile; ?>
Viewing 1 replies (of 1 total)
  • The topic ‘the_permalink() returns empty string inside the loop’ is closed to new replies.