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 -->
]]>My code is
Jquery
‘$(document).ready(function(){
$(“.flip”).click(function(){
$(“.panel”).slideToggle(“slow”);
});
});’
‘<?php if ( bp_has_members( “search_terms={$_POST[‘category’]}”)) : ?>
<?php while ( bp_members() ) : bp_the_member(); ?>
<div class=”flip”>Click to slide the panel down or up</div>
<div class=”panel”>Hello world!</div>
<?php endwhile; ?>
<?php endif; ?>’
How can i list specific members? or should I split (explode) the query string in an array and read the whole thing with PHP loop?
Maybe someone could help me or give a similar approach.
Thanks in advance
]]><?php for ($i = 1; $i <= 6; $i++) { ?>
<div class="two columns">
<div class="box-head">
<a>"><img src="<?php if(esc_url(of_get_option('box_image' . $i)) != NULL){ echo esc_url(of_get_option('box_image' . $i));} else echo get_template_directory_uri() . '/images/box' .$i. '.png' ?>" alt="<?php echo esc_html(of_get_option('box_head' . $i)); ?>" /></a>
</div> <!--box-head close-->
<div class="title-box">
<div class="title-head"><h1><?php if(esc_html(of_get_option('box_head' . $i)) != NULL){ echo esc_html(of_get_option('box_head' . $i));} else echo "Test1 heading" ?></h1></div></div>
<div class="box-content">
<?php if(esc_textarea(of_get_option('box_text' . $i)) != NULL){ echo esc_textarea(of_get_option('box_text' . $i));} else echo "Nullam posuere felis a lacus tempor eget dignissim arcu adipiscing. Donec est est, rutrum vitae bibendum vel, suscipit non metus." ?>
</div> <!--box-content close-->
<div class="clear"></div>
<span class="read-more"><a>"><?php _e('Read More' , 'discover'); ?></a></span>
</div><!--boxes end-->
[Please post code & markup between backticks or use the code button. Your posted code has now been permanently damaged by the forum’s parser.]
Thanks in advance to take your time to read. I’d appreciate any help.
]]><div id="resource">
<?php query_posts(array('showposts' => 20, 'post_parent' => 1950, 'post_type' => 'page')); while (have_posts()) { the_post(); ?>
<div class="video_thumbnail"><a href="<?php the_permalink(); ?>" title="<?php the_title();?>"><?php the_post_thumbnail('case-thumb'); ?></a></div>
<div class="video_title"><span class="rc-label"><a href="<?php the_permalink(); ?>"><img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php bloginfo('template_url'); ?>/images/blinds-subpage-image.jpg&w=120&h=120&zc=1" alt="<?php the_title(); ?>" /></a></span>
<?php the_content();?>
<a class="rc-button" target="_blank" href="<?php the_permalink(); ?>">Learn More</a></div><div class="clear"></div>
<?php } ?>
</div>
The problem is for some reason this code is stopping the sidebar from appearing.
<div id="subRight">
<?php get_sidebar(); ?>
</div><!--subRight-->
If I remove the loop code and leave the div blank, the sidebar appears so it has to be something involving this code. Any thoughts on why this would be a problem? Thank you!
]]>Got me a clients wants to manually choose for each page, which OTHER pages’ excerpts to display.
I know how to manually make the code for excerpts one by one …
(see the ‘bottom_article_1’ thingie below, it calls information from custom field)
… question is how do i dynamically create these in a loop according to what client fills in custom field. So if client fills one page id in custom field, only that excerpt show.
If client fills three pages id’s, three excerpts show.
Ideas?
global $post;
global $wp_query;
$active_page = $wp_query->post->ID;
$post_id = get_post_meta($active_page, 'bottom_article_1', true);
$queried_post = get_post($post_id);
$title = $queried_post->post_title;
$author = $queried_post->post_author;
$user_info = get_userdata($author);
$first_name = $user_info->first_name;
$last_name = $user_info->last_name;
]]>My client has over 11 “pages” listed. I would like to have it automatically split into 2-3 columns. I basically want to list 4 links in one column, 4 links in another and 3 links in the last column. I found this area of code in the post-template.php file (see below) is this where a loop will go?
function wp_list_pages($args = ”) {
742 $defaults = array(
743 ‘depth’ => 0, ‘show_date’ => ”,
744 ‘date_format’ => get_option(‘date_format’),
745 ‘child_of’ => 0, ‘exclude’ => ”,
746 ‘title_li’ => __(‘Pages’), ‘echo’ => 1,
747 ‘authors’ => ”, ‘sort_column’ => ‘menu_order, post_title’,
748 ‘link_before’ => ”, ‘link_after’ => ”
749 );
750
751 $r = wp_parse_args( $args, $defaults );
752 extract( $r, EXTR_SKIP );
753
754 $output = ”;
755 $current_page = 0;
756
757 // sanitize, mostly to keep spaces out
758 $r[‘exclude’] = preg_replace(‘/[^0-9,]/’, ”, $r[‘exclude’]);
759
760 // Allow plugins to filter an array of excluded pages
761 $r[‘exclude’] = implode(‘,’, apply_filters(‘wp_list_pages_excludes’, explode(‘,’, $r[‘exclude’])));
762
763 // Query pages.
764 $r[‘hierarchical’] = 0;
765 $pages = get_pages($r);
766
767 if ( !empty($pages) ) {
768 if ( $r[‘title_li’] )
769 $output .= ‘<li class=”pagenav”>’ . $r[‘title_li’] . ‘
‘;
770
771 global $wp_query;
772 if ( is_page() || is_attachment() || $wp_query->is_posts_page )
773 $current_page = $wp_query->get_queried_object_id();
774 $output .= walk_page_tree($pages, $r[‘depth’], $current_page, $r);
775
776 if ( $r[‘title_li’] )
777 $output .= ‘
‘;
778 }
779
780 $output = apply_filters(‘wp_list_pages’, $output, $r);
781
782 if ( $r[‘echo’] )
783 echo $output;
784 else
785 return $output;
786 }
====================
this is the php loop I found but I don’t know how to modify it and incorporate it into wordpress. any help would be great. here is the php loop code.
<?php
/*** the number of columns wide ***/
$num_cols = 3;
/*** and array to traverse ***/
$animals = array(
‘platypus’,
‘wallaby’,
‘dingo’,
‘wombat’,
‘kangaroo’,
‘steve irwin’,
’emu’,
‘kookaburra’,
‘crocodile’);
?>
<table>
<tr
style=”background:orange;”><td>Only</td><td>This</td><td>Wide</td></tr>
<?php
/*** set a counter ***/
$i = 0;
/*** loop over the array ***/
foreach ( $animals as $item )
{
/*** use modulo to check if the row should end ***/
echo $i++%$num_cols==0 ? ‘</tr><tr>’ : ”;
/*** output the array item ***/
echo ‘<td>’.$item.'</td>’;
}
?>
</tr>
</table>
I am having a problem bringing a Theme into the 21st century. Here is the loop code, what needs to be updated there to get it to work with 2.8? There is plenty of other stuff broken with the site that I a working on fixing (I didn’t create it), but this is one of the problems. Thanks!
<?php
$my_query = new WP_Query('cat=27&showposts=3');
if ($my_query->have_posts()) {
$n=1;
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div class="block_post_wrapper">
<div id="latest_news_<?php print $n; ?>" class="block_post">
<?php
$content = content('Read More...');
$contenti = extract_image( $content, 'homepage', 204, 205, true );
print '<img src="'.$contenti['resize'].'" class="align" />';
?>
<small class="meta"><?php the_date('F j, Y'); ?></small>
<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
<?php
if ($post->post_excerpt) {
the_excerpt();
} else {
print $contenti['content'];
}
?>
</div>
</div>
<?php
$n++;
endwhile;
}
?>
]]>