Two loops in a PHP file? Featured Image in a sidebar and post
-
I’m good with CSS and can sift my way through PHP.
I’m building a custom page template that has a page using a featured image in the sidebar – and it works great!
In the content area I would like to use a custom loop that pulls in one post from one category. I’ve got code for this but once inserted it wipes out my sidebar code.
I believe this is because they need to be apart of the same loop but my PHP knowledge is limited.I am including my code. If anyone knows what’s going on or can point me in the right direction to learn my way through it help would be so appreciated!
<?php /** * Template Name: Gov Template 2016 * * The template for displaying stream pages. * * @package ACMi Unity Theme */ ?> <!DOCTYPE html> <html <?php language_attributes(); ?>> <head> <meta charset="<?php bloginfo( 'charset' ); ?>"> <meta name="viewport" content="width=device-width"> <title><?php wp_title( '|', true, 'right' ); ?></title> <link rel="profile" href="https://gmpg.org/xfn/11"> <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>"> <?php wp_head(); ?> <link href='https://fonts.googleapis.com/css?family=Hind:600,700,500' rel='stylesheet' type='text/css'> </head> </html> <?php get_header(); ?> <div id="page-meagan" class="hfeed site"> <div id="content-meagan" class="site-content"> <div class="content-area"> <header class="entry-header-gov"> <h1 class="entry-title"><?php the_title(); ?></h1> </header><!-- .entry-header --> <div id="castus-contain-meagan"> <div id="castusstream-meagan"> <iframe width="800px" height="400px" frameborder="0" src="https://209.6.175.30/vodi/#castusvod_select=@live%3Ach3&castusvod_autoplay=1&nogui=1">Your browser does not support frames</iframe> </div> </div> <div id="content-meagan-2"> <?php the_content(); ?> </div> <div id="latestposts-meagan"> <div class="feed"> <?php $rss = new DOMDocument(); $rss->load('https://acmi.tv/category/government/feed/'); $feed = array(); foreach ($rss->getElementsByTagName('item') as $node) { $item = array ( 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue, 'thumbnail' => $node->getElementsByTagName('thumbnail')->item(0)->nodeValue, ); array_push($feed, $item); } $limit = 1; for($x=0;$x<$limit;$x++) { $title = str_replace(' & ', ' & ', $feed[$x]['title']); $link = $feed[$x]['link']; $description = $feed[$x]['desc']; $date = date('l F d, Y', strtotime($feed[$x]['date'])); echo '<p><h2><a href="'.$link.'" title="'.$title.'">'.$title.'</a></h2>'; echo '<small><em>Posted on '.$date.'</em></small></p>'; echo '<p>'.$description.'</p>'; } ?> </div></div> <div id="latestgov-meagan"> <?php $query_gov = new WP_Query( 'cat=95&showposts=1' ); // Localhost = Cat ID#10 | Live Host = Cat ID#95 ?> <?php while ($query_gov -> have_posts()) : $query_gov -> the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <header class="entry-header"> <h3 class="entry-title">Government Spotlight:</h3> </header><!-- .entry-header --> <div class="post-thumb"> <?php $poster_image = wp_get_attachment_image_src(get_field('thumbnail'), 'unity-preview-small'); ?> <?php if(get_field('thumbnail') !== false): ?> <a>" class="poster"> <div class="thumb-overlay"></div> <img src="<?php echo $poster_image[0]; ?>"> </a> <?php else: ?> <a>" class="poster"> <div class="thumb-overlay"></div> <img src="<?php echo get_template_directory_uri() . '/img/acmi-thumb-180.png'; ?>"> </a> <?php endif; ?> </div> <div class="entry-content"> <h4><a>"><?php the_title(); ?></a></h4> <p><?php the_excerpt(__('(more…)')); ?></p> </div><!-- .entry-content --> <?php edit_post_link( __( 'Edit', 'acmi_unity' ), '<footer class="entry-meta"><span class="edit-link">', '</span></footer>' ); ?> </article><!-- #post-## --> <?php endwhile;?> </div><!-- #latestgov --> </div><!-- #content-area --> </div><!-- #content-meagan --> <div id="sidebar-area"> <?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?> <?php get_sidebar(); ?> </div> <?php get_footer(); ?> </div><!-- #page -->
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Two loops in a PHP file? Featured Image in a sidebar and post’ is closed to new replies.