Not able to pull in featured image - php

I'm using a wordpress theme as a base to provide horizontal parallax scrolling. I have everything working wonderfully, but when I try to pull the featured image into the page (see CONTENT), nothing will pull up. I can get a static image to show up, but not with any amount of tags or even custom fields. Here is the code for the page:
<?php
/**
* The main file.
*/
get_header(); ?>
<?php require( dirname( __FILE__ ) . "/inc/theme-options-vars.php" ); ?>
<!-- ==================== PARALLAX FUNCTIONS ==================== -->
<?php for( $i=1; $i<=($numposts); $i++ )
{
echo '<div class="hw" id="page-'.$i.'">';
} ?>
<!-- ==================== PARALLAX FUNCTIONS ==================== -->
<?php if($convax_bg1!==''){
echo'
<div class="elem-1">
<div class="elem-1-bg"></div>
</div>';
}
if($convax_bg2!==''){
echo'
<div class="elem-2">
<div class="elem-2-bg"></div>
</div>';
}
?>
<div class="hw" id="content-inner">
<?php
$pages = get_pages( 'sort_order=asc&sort_column=menu_order&depth=1' );
foreach ( $pages as $pag ) {
setup_postdata( $pag );
$new_title = str_replace( " ", "", strtolower( $pag->post_title ) );
$tempname = get_post_meta( $pag->ID, '_wp_page_template', true );
$filename = preg_replace('"\.php$"', '', $tempname);
echo '<div class="page '.$new_title;
echo '" id="' . $new_title . '"><div class="page-info">';
if ( $new_title !== 'home' ) {
echo '<h1>';
echo $pag->post_title;
$pag->post_title;
echo '</h1>';
}
?>
<!-- If Portfolio Page -->
<?php if($filename == 'page-portfolio'):?>
<?php query_posts( array( 'post_type' => 'portfolio_item', 'orderby' => 'date', 'order' => 'ASC' ) ); ?>
<?php if(have_posts()): ?>
<div class="scrollbar1">
<div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div>
</div></div></div>
<div class="viewport">
<div class="overview">
<div class="rec-proj">
<ul>
<?php while ( have_posts() ) : the_post(); ?>
<li>
<a href="#port-<?php echo $post->ID ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'convaxsolutions' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark" class="various">
<?php
if(has_post_thumbnail()) {
the_post_thumbnail('thumbnail');
} else {
echo '<img src="'.get_bloginfo("template_url").'/images/default-featured-image.png" class="portfolio-thumb" width="60" height="60"/>';
}
?>
</a>
<?php edit_post_link('Edit'); ?>
</li>
<?php endwhile; ?>
</ul>
</div><!-- / rec proj -->
</div><!-- / .overview -->
</div><!-- / .viewport -->
</div><!-- / .Scrollbar1 -->
<?php else: ?>
<h1 class="alert"></h1>
<?php endif; ?>
<?php else: ?>
<div class="scrollbar1">
<div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div> </div></div></div>
<div class="viewport">
<!-- ==================== CONTENT ==================== -->
<div class="overview">
<?php the_content(); ?>
<?php the_post_thumbnail('full'); ?>
</div>
<!-- ==================== CONTENT ==================== -->
</div><!-- / .viewport -->
</div><!-- / .Scrollbar1 -->
<?php endif; ?>
<!-- End If Portfolio-->
<?php echo '</div></div>';
}
?>
<!-- End foreach -->
</div>
<!-- / #content-inner -->
<?php for( $i=1; $i<=($numposts); $i++ )
{
echo '</div>';
} ?>
<?php get_footer(); ?>
Thanks!

Please see the documentation! Get the image with:
get_the_post_thumbnail($pag->ID, 'full');
Documentation for the_post_thumbnail($size, $attr);
This tag must be used within The Loop. Use get_the_post_thumbnail($id,
$size, $attr ) instead to get the featured image for any post.
http://codex.wordpress.org/Function_Reference/the_post_thumbnail

Related

Modifying Wordpress PHP dynamic content

My page is bewitcheryinc.com
I am trying to re-arrange my home page. I need to switch the promotional area (section with 3 rectangles) with the text below it. I need to have the text displayed first and then the promotional area (section with 3 rectangles). I have contacted theme support, and they told me that the content is dynamic and the only solution to try is to replace header.php with the following code.
<?php
/**
* Displays the header content
*
* #package Theme Freesia
* #subpackage Edge
* #since Edge 1.0
*/
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<?php
$edge_settings = edge_get_theme_options(); ?>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<div id="page" class="hfeed site">
<!-- Masthead ============================================= -->
<header id="masthead" class="site-header">
<?php if ( function_exists( 'the_custom_header_markup' ) ) {
if ( is_header_video_active() && ( has_header_video() || is_customize_preview() ) ) {
echo '<div class="custom-header">
<div class="custom-header-media">';
the_custom_header_markup();
echo '</div>
</div>';
}else{
if ( has_header_image() ) {?>
<img src="<?php header_image(); ?>" class="header-image" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="<?php echo esc_attr(get_bloginfo('name', 'display'));?>" />
<?php }
}
} else { ?>
<img src="<?php header_image(); ?>" class="header-image" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="<?php echo esc_attr(get_bloginfo('name', 'display'));?>" />
<?php } ?>
<div class="top-header">
<div class="container clearfix">
<?php
if( is_active_sidebar( 'edge_header_info' )) {
dynamic_sidebar( 'edge_header_info' );
}
if($edge_settings['edge_top_social_icons'] == 0):
echo '<div class="header-social-block">';
do_action('social_links');
echo '</div>'.'<!-- end .header-social-block -->';
endif;
do_action('edge_site_branding'); ?>
</div> <!-- end .container -->
</div> <!-- end .top-header -->
<!-- Main Header============================================= -->
<div id="sticky_header">
<div class="container clearfix">
<h3 class="nav-site-title">
<?php bloginfo('name');?>
</h3>
<!-- end .nav-site-title -->
<!-- Main Nav ============================================= -->
<?php
if (has_nav_menu('primary')) { ?>
<?php $args = array(
'theme_location' => 'primary',
'container' => '',
'items_wrap' => '<ul id="primary-menu" class="menu nav-menu">%3$s</ul>',
); ?>
<nav id="site-navigation" class="main-navigation clearfix">
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false">
<span class="line-one"></span>
<span class="line-two"></span>
<span class="line-three"></span>
</button>
<!-- end .menu-toggle -->
<?php wp_nav_menu($args);//extract the content from apperance-> nav menu ?>
</nav> <!-- end #site-navigation -->
<?php } else {// extract the content from page menu only ?>
<nav id="site-navigation" class="main-navigation clearfix">
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false">
<span class="line-one"></span>
<span class="line-two"></span>
<span class="line-three"></span>
</button>
<!-- end .menu-toggle -->
<?php wp_page_menu(array('menu_class' => 'menu', 'items_wrap' => '<ul id="primary-menu" class="menu nav-menu">%3$s</ul>')); ?>
</nav> <!-- end #site-navigation -->
<?php }
$search_form = $edge_settings['edge_search_custom_header'];
if (1 != $search_form) { ?>
<div id="search-toggle" class="header-search"></div>
<div id="search-box" class="clearfix">
<?php get_search_form();?>
</div> <!-- end #search-box -->
<?php }
echo '</div> <!-- end .container -->
</div> <!-- end #sticky_header -->';
$enable_slider = $edge_settings['edge_enable_slider'];
edge_slider_value();
if ($enable_slider=='frontpage'|| $enable_slider=='enitresite'){
if(is_front_page() && ($enable_slider=='frontpage') ) {
if($edge_settings['edge_slider_type'] == 'default_slider') {
edge_page_sliders();
}else{
if(class_exists('Edge_Plus_Features')):
edge_image_sliders();
endif;
}
}
if($enable_slider=='enitresite'){
if($edge_settings['edge_slider_type'] == 'default_slider') {
edge_page_sliders();
}else{
if(class_exists('Edge_Plus_Features')):
edge_image_sliders();
endif;
}
}
} ?>
</header> <!-- end #masthead -->
<!-- Main Page Start ============================================= -->
<div id="content">
<div class="container clearfix">
<?php
if(is_front_page()){
if( have_posts() ) {
while( have_posts() ) {
the_post();
get_template_part( 'content', get_post_format() );
}
} else { ?>
<h2 class="entry-title"> <?php esc_html_e( 'No Posts Found.', 'edge' ); ?> </h2>
<?php }
do_action('edge_display_frontpage_features');
}
if(!is_home()){?>
<div class="page-header">
<h1 class="page-title"><?php echo edge_header_title(); ?></h1>
<!-- .page-title -->
<?php edge_breadcrumb(); ?>
<!-- .breadcrumb -->
</div>
<!-- .page-header -->
<?php }
After I replace headr.php, I have to add the following css:
.home .entry-header, .home .entry-meta, section#post-417, .home .entry-footer {
display:none;
}
When I follow these instructions, the home page displays my original page text as a blog post with "read more" tags, along with the meta tags. The read more link links back to the home page. I simply want the front page to display my page title, some text, and then the promotional picture boxes.
If it is helpful, I beleive that when promotional area is turned on, the theme uses front-page-feature.php template instead of an index page. It is bellow.
<?php
function edge_frontpage_features(){
$edge_settings = edge_get_theme_options();
if($edge_settings['edge_disable_features'] != 1){
$edge_features = '';
$edge_total_page_no = 0;
$edge_list_page = array();
for( $i = 1; $i <= $edge_settings['edge_total_features']; $i++ ){
if( isset ( $edge_settings['edge_frontpage_features_' . $i] ) && $edge_settings['edge_frontpage_features_' . $i] > 0 ){
$edge_total_page_no++;
$edge_list_page = array_merge( $edge_list_page, array( $edge_settings['edge_frontpage_features_' . $i] ) );
}
}
if ( !empty( $edge_list_page ) && $edge_total_page_no > 0 ) {
echo '<!-- Promotional Area ============================================= -->';
$edge_features .= '<div class="promonational-area">';
$get_featured_posts = new WP_Query(array(
'posts_per_page' => $edge_settings['edge_total_features'],
'post_type' => array('page'),
'post__in' => $edge_list_page,
'orderby' => 'post__in',
));
$edge_features .= '<div class="column clearfix">';
$j = 1;
while ($get_featured_posts->have_posts()):$get_featured_posts->the_post();
$attachment_id = get_post_thumbnail_id();
$image_attributes = wp_get_attachment_image_src($attachment_id,'pixgraphy_promotional_image');
$excerpt = get_the_excerpt();
$edge_features .= '<div class="three-column">';
if ($image_attributes) {
$edge_features .= '<div class="promonational-img" title="'.the_title('', '', false).'"' .' style="background-image:url(' ."'" .esc_url($image_attributes[0])."'" .')"> <a class="promonational-link" href="'.get_the_permalink().'"></a> ';
$edge_features .= '<div class="promonational-overlay">
<h4>'.get_the_title().'</h4></div></div>';
}
$edge_features .='</div><!-- end .three-column -->';
$j++;
endwhile;
$edge_features .='</div><!-- .end column-->';
$edge_features .='</div><!-- end .promonational-area -->';
}
echo $edge_features;
}
wp_reset_postdata();
}
add_action('edge_display_frontpage_features','edge_frontpage_features');
Can anyone help? I am not proficient obviously in PHP/WordPress at all. Thank you!
I think this would work:
In index.php move the
if(is_front_page()){
do_action('edge_display_frontpage_features');
}
right before
get_template_part( 'pagination', 'none' );
in header.php.
This would put the front-page feature after the 'main' content in the primary section of the post. Now you need to figure out how to put the right post content for the text. Currently it seems like it's not fetching the correct post type. It's probably the sample post in the post post type.
But is the text supposed to be static or changes with your recently posted content? If its supposed to static, you should go in Settings->Reading in the admin dashboard and set the front-page to a static page and then you can put in the text into that page content.

wordpress: show posts in two columns

I have a theme that shows the latest four posts in one column. I want to convert this to two posts in two columns.
I made two divs next to each other and put the first in descending order and the other in ascending order. Then I set it to show only 2 posts.
But now it shows 2 posts in the left div and all four posts in the right div:
I don't understand why it is doing this. Here is the code:
<section class="container">
<div class="left-half">
<article>
<!-- =========================
SECTION: LATEST NEWS
============================== -->
<?php
$parallax_number_of_posts = get_option('posts_per_page');
$args = array( 'post_type' => 'post', 'posts_per_page' => $parallax_number_of_posts, 'order' => 'ASC','ignore_sticky_posts' => true );
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
$parallax_one_latest_news_title = get_theme_mod('parallax_one_latest_news_title',esc_html__('Latest news','parallax-one'));
if($parallax_number_of_posts > 0) {
?>
<section class="brief timeline" id="latestnews" role="region" aria-label="<?php esc_html_e('Latest blog posts','parallax-one'); ?>">
<div class="section-overlay-layer">
<div align="center" class="container">
<div class="row">
<!-- TIMELINE HEADING / TEXT -->
<?php
if(!empty($parallax_one_latest_news_title)){
echo '<div class="col-md-12 timeline-text text-left"><h2 class="text-left dark-text">'.esc_attr($parallax_one_latest_news_title).'</h2><div class="colored-line-left"></div></div>';
} elseif ( isset( $wp_customize ) ) {
echo '<div class="col-md-12 timeline-text text-left paralax_one_only_customizer"><h2 class="text-left dark-text "></h2><div class="colored-line-left "></div></div>';
}
?>
<div class="parallax-slider-whole-wrap">
<!--<div class="controls-wrap">
<button class="control_next icon icon-arrow-carrot-down"><span class="screen-reader-text"><?php esc_attr_e('Post slider navigation: Down','parallax-one')?></span></button>
<button class="control_prev fade-btn icon icon-arrow-carrot-up"><span class="screen-reader-text"><?php esc_attr_e('Post slider navigation: Up','parallax-one')?></span></button>
</div>-->
<!-- TIMLEINE SCROLLER -->
<div itemscope itemtype="http://schema.org/Blog" id="parallax_slider" class="col-md-6 timeline-section">
<ul class="vertical-timeline" id="timeline-scroll">
<?php
$i_latest_posts= 0;
while ( $the_query->have_posts() ) : $the_query->the_post();
$i_latest_posts++;
if ( !wp_is_mobile() ){
if($i_latest_posts % 2 == 1){
echo '<li>';
}
} else {
echo '<li>';
}
?>
<div itemscope itemprop="blogPosts" itemtype="http://schema.org/BlogPosting" id="post-<?php the_ID(); ?>" class="timeline-box-wrap" title="<?php printf( esc_html__( 'Latest News: %s', 'parallax-one' ), get_the_title() ) ?>">
<div itemscope itemprop="image" class="icon-container white-text">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php
if ( has_post_thumbnail() ) :
the_post_thumbnail('parallax-one-post-thumbnail-latest-news');
else: ?>
<img src="<?php echo parallax_get_file('/images/no-thumbnail-latest-news.jpg'); ?>" width="150" height="150" alt="<?php the_title(); ?>">
<?php
endif;
?>
</a>
</div>
<div class="info">
<header class="entry-header">
<h1 itemprop="headline" class="entry-title"><br><br><br>
<?php the_title(); ?>
</h1>
<!-- .entry-meta -->
</header>
<div itemprop="description" class="entry-content entry-summary">
<?php the_excerpt(); ?>
<?php printf( esc_html__( 'Bekijk de fotos %s', 'textdomain' ), '<span class="screen-reader-text"> '.get_the_title().'</span>' ); ?>
</div>
</div>
</div>
<?php
if ( !wp_is_mobile() ){
if($i_latest_posts % 2 == 0){
echo '</li>';
}
} else {
echo '</li>';
}
endwhile;
wp_reset_postdata();
?>
</ul>
</div>
</div><!-- .parallax-slider-whole-wrap -->
</div>
</div>
</div>
</section>
<?php
}
} ?>
</article>
</div>
<!--rechts-->
<div class="right-half">
<article>
<!-- =========================
SECTION: LATEST NEWS
============================== -->
<?php
$parallax_number_of_posts = get_option('posts_per_page');
$args = array( 'post_type' => 'post', 'posts_per_page' => $parallax_number_of_posts, 'order' => 'DESC','ignore_sticky_posts' => true );
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
$parallax_one_latest_news_title = get_theme_mod('parallax_one_latest_news_title',esc_html__('Latest news','parallax-one'));
if($parallax_number_of_posts > 0) {
?>
<section class="brief timeline" id="latestnews" role="region" aria-label="<?php esc_html_e('Latest blog posts','parallax-one'); ?>">
<div class="section-overlay-layer">
<div align="center" class="container">
<div class="row">
<!-- TIMELINE HEADING / TEXT -->
<br>
<br>
<br>
<div class="parallax-slider-whole-wrap">
<div class="controls-wrap">
<button class="control_next icon icon-arrow-carrot-down"><span class="screen-reader-text"><?php esc_attr_e('Post slider navigation: Down','parallax-one')?></span></button>
<button class="control_prev fade-btn icon icon-arrow-carrot-up"><span class="screen-reader-text"><?php esc_attr_e('Post slider navigation: Up','parallax-one')?></span></button>
</div>
<!-- TIMLEINE SCROLLER -->
<div itemscope itemtype="http://schema.org/Blog" id="parallax_slider" class="col-md-6 timeline-section">
<ul class="vertical-timeline" id="timeline-scroll">
<?php
$i_latest_posts= 0;
while ( $the_query->have_posts() ) : $the_query->the_post();
$i_latest_posts++;
if ( !wp_is_mobile() ){
if($i_latest_posts % 2 == 1){
echo '<li>';
}
} else {
echo '<li>';
}
?>
<div itemscope itemprop="blogPosts" itemtype="http://schema.org/BlogPosting" id="post-<?php the_ID(); ?>" class="timeline-box-wrap" title="<?php printf( esc_html__( 'Latest News: %s', 'parallax-one' ), get_the_title() ) ?>">
<div itemscope itemprop="image" class="icon-container white-text">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php
if ( has_post_thumbnail() ) :
the_post_thumbnail('parallax-one-post-thumbnail-latest-news');
else: ?>
<img src="<?php echo parallax_get_file('/images/no-thumbnail-latest-news.jpg'); ?>" width="150" height="150" alt="<?php the_title(); ?>">
<?php
endif;
?>
</a>
</div>
<div class="info">
<header class="entry-header">
<h1 itemprop="headline" class="entry-title"><br><br><br>
<?php the_title(); ?>
</h1>
<!-- .entry-meta -->
</header>
<div itemprop="description" class="entry-content entry-summary">
<?php the_excerpt(); ?>
<?php printf( esc_html__( 'Bekijk de fotos %s', 'textdomain' ), '<span class="screen-reader-text"> '.get_the_title().'</span>' ); ?>
</div>
</div>
</div>
<?php
if ( !wp_is_mobile() ){
if($i_latest_posts % 2 == 0){
echo '</li>';
}
} else {
echo '</li>';
}
endwhile;
wp_reset_postdata();
?>
</ul>
</div>
</div><!-- .parallax-slider-whole-wrap -->
</div>
</div>
</div>
</section>
<?php
}
} ?>
</article>
</div>
</section>
If I understood correctly what you want to achieve - to divide several posts into two columns, I can not understand exactly how you want to achieve this into code. If you rely on this condition $the_query->current_post % 2 == 1 to filter the posts, then in your code it only filter printing of the li element, but then the cycle continues and show the post itself, ie what you achieve with this code is to place two posts (div.timeline-box-wrap) elements in one li.If you want to use this method of separation, you should change the code a little (I will simplify it, but the main is, that you must stop current loop if your condition pass).
You don't need to query DB two times with the same query - this is performance issue, so you can use the same result and loop over two times.
You can use $the_query->current_post to get current post and filter.
<section class="container">
<div class="left-half">
<article>
<?php
$parallax_number_of_posts = get_option('posts_per_page');
$args = array( 'post_type' => 'product', 'posts_per_page' => $parallax_number_of_posts, 'order' => 'ASC','ignore_sticky_posts' => true );
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
if($parallax_number_of_posts > 0) {
?>
<section class="brief timeline" id="latestnews" role="region" aria-label="<?php esc_html_e('Latest blog posts','parallax-one'); ?>">
<ul class="vertical-timeline" id="timeline-scroll">
<?php while ( $the_query->have_posts() ) : $the_query->the_post();
if($the_query->current_post % 2 == 1)
continue; ?>
<li><?php the_title() ?></li>
<?php endwhile; ?>
</ul>
</section>
<?php
}
} ?>
</article>
</div>
<div class="right-half">
<article>
<?php
$the_query->rewind_posts();
if ( $the_query->have_posts() ) {
if($parallax_number_of_posts > 0) {
?>
<section class="brief timeline" id="latestnews" role="region" aria-label="<?php esc_html_e('Latest blog posts','parallax-one'); ?>">
<ul class="vertical-timeline" id="timeline-scroll">
<?php while ( $the_query->have_posts() ) : $the_query->the_post();
if($the_query->current_post % 2 == 0)
continue; ?>
<li><?php the_title() ?></li>
<?php endwhile; ?>
</ul>
</section>
<?php
}
} ?>
</article>
</div>
</section>
P.S. You can simplify more, if you set 2 variables: $left and $right and use only one loop to set one or other with html, and then print their values.

I want to display sub category post only in sub category but not in parent category

<?php get_header(); ?>
<section id="container" class="<?php echo tempera_get_layout_class(); ?>">
<div id="content" role="main">
<?php if ( have_posts() ) : ?>
This is the code to display sub category in a category page with images
<?php $this_category = get_category($cat); ?>
<ul style="line-height: 5.7em;">
<?php $id = get_query_var('cat');
$args = array('parent' => $id );
$catdesc = $cat->category_description;
foreach (get_categories($args) as $cat):?>
<a href="<?php echo get_category_link($cat->term_id); ?>">
<img style= "width:250px; height:150px; padding-left:20px; margin-top:20px;" src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />
<div style="display:inline-block;position:absolute;margin-left:-150px;margin-top:150px;"><?php echo ("$cat->cat_name"); ?></div></a>
<?php endforeach ?>
</ul>
Here the code ends for displaying sub category
<?php
$category_description = category_description();
if ( ! empty( $category_description ) )
echo apply_filters( 'category_archive_meta', '<div class="category- archive-meta">' . $category_description . '</div>' );
?>
</header>
<?php while ( have_posts() ) : the_post(); ?>
<?php
get_template_part( 'content/content', get_post_format() );
?>
<?php endwhile; ?>
<?php if($tempera_pagination=="Enable") tempera_pagination(); else tempera_content_nav( 'nav-below' ); ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'tempera' ); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'tempera' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</article><!-- #post-0 -->
<?php endif; ?>
<?php cryout_after_content_hook(); ?>
</div><!-- #content -->
<?php tempera_get_sidebar(); ?>
</section><!-- #primary -->
<?php get_footer(); ?>
The problem is that all the posts in the category display under the category and the subcategory.
But i want to display posts under that subcategory only, not in category.
So please any one give me suggestions
Please use the below code. It will help you.
$category = '{enter your category name here}';
$categoryID = get_cat_ID($category);
$subcategories = get_categories('child_of=' . $categoryID);
foreach($subcategories as $subcategory) {
$subcategory_posts = get_posts('cat=' . $subcategory->cat_ID);
foreach($subcategory_posts as $subcategory_post) {
$postID = $subcat_post->ID;
echo get_the_title($postID);
}
}

WordPress Sidebar on single.php

So, my sidebar is working just fine on my blog page: beta.cleantelligent.com/blog
However, when you click a single post, I'd like that same sidebar to show up.
I am assuming this would be under single.php, right? That code is listed below. Let me know if you need any other code and I'll post it here.
I have the 'blog' sidebar in my page attributes on the Edit Page in Wordpress, but it's just not being recognized by the template, I guess?
Any help would be great. Thanks!
<?php
get_header(); ?>
<div class="blackbar">
<div class='bbw'>
Blog
</div>
</div>
<div class='cont-wrap'>
<div id="primary">
<?php
$post_obj = $wp_query->get_queried_object();
$post_name = $post_obj->post_name;
if($post_name == 'blog'){
echo 'Blog';
}else{
$parent_title = get_the_title($post->post_parent);
echo $parent_title;
}
?>
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'archive' ); ?>
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
</div>
The blog page is using index.php
<?php
get_header(); ?>
<div class="blackbar">
<div class='bbw'>
<?php
$post_obj = $wp_query->get_queried_object();
$post_name = $post_obj->post_name;
if($post_name == 'blog'){
echo 'Blog';
}else{
$parent_title = get_the_title($post->post_parent);
echo $parent_title;
}
?>
</div>
</div>
<div class='cont-wrap'>
<div id="primary">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'blog' ); ?>
<?php comments_template( '', false ); ?>
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
</div>
</div><!-- #main -->
Here is my sidebar.php:
<?php
$options = twentyeleven_get_theme_options();
$current_layout = $options['theme_layout'];
$nav = sb_get_page_nav($post);
if ( 'content' != $current_layout ) :
?>
<img class="sidebar-top" src='<?php bloginfo('stylesheet_directory'); ?>/images/sidebar-top.png' />
<div id="secondary" class="widget-area" role="complementary">
<?php
$post_obj = $wp_query->get_queried_object();
$post_name = $post_obj->post_name;
$title = 'cs-' . $post_name;
?>
<?php
if($post_name == 'news-events'){
if ( ! dynamic_sidebar( 'sidebar-web' ) ) :
endif;
}
?>
<?php if(!$nav['no_nav']) { ?>
<div class="SimpleSideNav">
<?php wp_nav_menu(array('container_id' => 'left-navigation','menu' => $nav['title'])); ?>
</div>
<?php } ?>
<?php if ( ! dynamic_sidebar( 'sidebar-all' ) ) : ?>
<?php endif; // end sidebar widget area ?>
<?php /*
<nav id="left-nav">
<div class="nav-wrapper">
<?php if(!$nav['no_nav']) {
wp_nav_menu(array('container_id' => 'left-navigation','menu' => $nav['title']));
} ?>
</div>
</nav>
*/ ?>
<?php if ( ! dynamic_sidebar( $title ) ) : ?>
<?php endif; // end sidebar widget area ?>
<img class="sidebar-bot" src='<?php bloginfo('stylesheet_directory'); ?>/images/sidebar-bot.png' />
</div><!-- #secondary .widget-area -->
<?php endif;
$parent_title = get_the_title($post->post_parent);
if($parent_title == 'Tour'){
echo"
<script>
jQuery('.w-1').hide();
</script>
";
}
?>
I fixed it by creating a brand new sidebar under sidebar-blog.php and redirecting my templates to it.

wordpress custom - add class to the first blog

here is my blog page template:
<?php
/**
* Template Name: Blog
*
* Standard blog template, create a static page for your blog and select this as the template.
*
* The "Template Name:" bit above allows this to be selectable
* from a dropdown menu on the edit page screen.
*/
get_header(); ?>
<div id="main_container">
<!-- IE7 float fix --><!--[if lt IE 7]><span class="iefix">.</span><![endif]-->
<div class="main">
<div class="entries_full">
<div class="entry_full">
<div class="box_twothirds mt30 pr60">
<!-- BLOG POSTS BEGIN -->
<?php
$exclude_cat = get_option('bb_exclude_cat');
$exclude_temp = str_replace(",", ",-", $exclude_cat);
$exclude_cats = "-" . $exclude_temp;
$blog_posts = get_option('bb_blog_posts');
if($blog_posts == NULL) {$blog_posts = '5';}
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query('cat=' . $exclude_cats . '&paged=' . $paged . '&showposts=' . $blog_posts);
$count = 0;
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
<div class="blog">
<!-- displays the blog posts -->
<?php $count++; if($count > 3) { $count = 1; } ?>
<h3 class="<?php if($count > 1) echo "mt25 "; ?>mb12"><?php the_title(); ?></h3>
<?php if(get_post_meta($post->ID, large_image_value, $single = true) != NULL || get_post_meta($post->ID, fullsize_value, $single = true) != NULL)
{ ?>
<div class="mag_blog"><!-- magnifying glass div -->
<img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php if (get_post_meta($post->ID, large_image_value, true) != NULL) {echo get_post_meta($post->ID, large_image_value, $single = true);} else if (get_post_meta($post->ID, fullsize_value, true) != NULL) {echo get_post_meta($post->ID, fullsize_value, $single = true);} else {echo get_post_meta($post->ID, accordion_image_value, true);} ?>&h=213&w=600&zc=1" alt="<?php the_title(); ?>" />
</div><!-- end magnifying glass div -->
<?php } ?>
<p class="meta"><span class="postdate"><?php the_time('F jS, Y') ?></span><span class="tags"><?php the_category(', '); ?></span><span class="comments"><?php comments_number('0 comments','1 comment','% comments'); ?></span></p>
<?php global $more; $more = false; ?><?php the_content('<span>Continue Reading</span>'); ?><?php $more = true; ?>
<div class="bar mt25 mb30"></div>
<?php comments_template( '', true ); ?>
</div>
<?php endwhile;
if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { ?>
<?php /* Display navigation to next/previous pages when applicable */ ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<?php next_posts_link( __( '← Older posts', 'twentyten' ) ); ?>
<?php previous_posts_link( __( 'Newer posts →', 'twentyten' ) ); ?>
<?php endif; ?>
<?php }
$wp_query = null; $wp_query = $temp; ?>
<!-- BLOG POSTS END -->
</div>
<!-- Begin Sidebar -->
<?php include('sidebar.php'); ?>
<!-- end sidebar -->
<div class="clear"></div>
</div><!-- end div.entry -->
</div><!-- end div.entries -->
<div class="clear"></div>
</div><!-- end div#main -->
<div class="clear"></div>
</div><!-- end div#main_container-->
<?php get_footer(); ?>
</code>
Just wonder if there is a way to add a class to the first blog item, or a way to make the first block item has different style than the rest... Or I need to edit on other php file?
Thanks guys.
You can do exactly that within the first line of your while() loop:
Replace:
<div class="blog">
With:
<div class="blog<?php if ($count === 0) echo " first_post"; ?>">
That should add a custom class to the first blog item on the page called 'first_post'.

Categories