I have a loop on my homepage showing 3 recent blog posts, this is being included in from the footer. If I go elsewhere on the site though such as a different blog post, the 'the_permalink' is instead of grabbing the featured 3 blog post links, it's grabbing the link from the page your currently on.
These 3 blog posts will change as new ones are added so I cannot define that the link be only a specific blog post(s).
Here is the code showing the first blog post. Found within footer.php and therefore shows on each page.
<div id="news-container-1">
<?php
// Create a variable to hold our custom Loop results
$excludes = array('4135');
$frontpageposts = get_posts( array(
'numberposts' => 1, // only the 3 latest posts
'post__not_in' => $excludes
) );
// Create output only if we have results
// Customize to suit your HTML markup
if ( $frontpageposts ) {
foreach ( $frontpageposts as $fppost ) {
// setup postdata, so we can use template tags
setup_postdata($fppost);
?>
<div <?php post_class(); ?>>
<h4><a href="<?php the_permalink(1); ?>"><?php //the_title(); ?>Latest News #1</a></h4>
<div class="post-entry">
<?php
$content = $post->post_content;
$searchimages = '~<img [^>]* />~';
/*Run preg_match_all to grab all the images and save the results in $pics*/
preg_match_all( $searchimages, $content, $pics );
// Check to see if we have at least 1 image
$iNumberOfPics = count($pics[0]);
if ( $iNumberOfPics > 0 ) { ?>
<!-- GRAB THE IMAGE AND USE WHATEVER HTML YOU LIKE -->
<img src="<?php echo catch_that_image() ?>" alt="<?php the_title(); ?>" /></a>
<?php }
?>
<?php //the_excerpt(); ?>
</div>
</div>
<?php }
}
?>
</div>