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'.
Related
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.
I need to have a different layout for the first post in every page, but don't know where to start. The code is the following:
<?php get_header(); ?>
<div class="row">
<section class="small-12 columns grid-style">
<?php $i = 0; $counter = range(0, 200, 3); ?>
<?php
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$args = array('offset'=> 0, 'paged'=>$paged);
$all_posts = new WP_Query($args);
if (have_posts()) : while($all_posts->have_posts()) : $all_posts->the_post();?>
<?php if ($i % 3 == 0) { echo '<div class="row journal" data-equal=".post">'; } ?
<!--Post -->
<article class="grid-style post" id="post-<?php the_ID(); ?>"
<div class="post-img">
<?php get_template_part( 'inc/postformats/grid-style' ); ?>
</div>
<div class="post-box">
<div class="post-title">
<h2><?php echo ShortenText(get_the_title(), 50); ?></h2>
</div>
<aside class="post_categories">
<?php the_category(', '); ?>
</aside>
<div class="post-content">
<?php echo ShortenText(get_the_excerpt(), 170); ?>
</div>
</div>
</article>
<!--/Post -->
<?php if (in_array($i + 1, $counter)){ echo '</div>'; } ?>
<?php $i++; endwhile; ?>
<div class="small-12 columns">
<?php theme_pagination($all_posts->max_num_pages, 1, true); ?>
</div>
<?php else : ?>
<p><?php _e( 'Please add posts from your WordPress admin page.', THB_THEME_NAME ); ?></p>
<?php endif; ?>
</section>
</div>
<?php get_footer(); ?>
I need to use a different image size, so I need to output everything inside < ! - - Post - - > again for the first post only.
Are you trying to include div.row.journal to the first post?
If it's the case try doing this:
Replace <?php if ($i % 3 == 0) { echo '<div class="row journal" data-equal=".post">'; } ? by the following: (It'll echo it only on the first page, for the first post)
<?php
if ($all_posts->current_post == 0 && !is_paged()) {
echo '<div class="row journal" data-equal=".post">';
}
?>
Doing the same for the closing div by replacing <?php if (in_array($i + 1, $counter)){ echo '</div>'; } ?> by :
<?php
if ($all_posts->current_post == 0 && !is_paged()) {
echo '</div>';
}
?>
You have to define a counter and ask with if...else... inside the loop
$post_counter = 1;
while (start_loop):
if ($post_counter == 1){
echo "<div id='1'></div>";
else:
echo "<div id='2'></div>";
$post_counter += 1;
//end loop
I think that should help you.
This is the code I have now, I was able to output the HTML for the first post, and a different one for ALL the posts, but I am getting 2 first posts. One using the first layout and the second using the second layout
<?php
/*
Template Name: Blog - Grid Style
*/
?>
<?php get_header(); ?>
<div class="row">
<section class="small-12 columns grid-style">
<?php $i = 0; $counter = range(0, 200, 3); ?>
<?php
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$args = array('offset'=> 0, 'paged'=>$paged);
$all_posts = new WP_Query($args);
$post_counter = 0;
if (have_posts()) : while($all_posts->have_posts()) : $all_posts->the_post(); $post_counter++;?>
<?php if ($i % 3 == 0) { echo '<div class="row journal" data-equal=".post">'; } ?>
<?php if ($post_counter == 1){ ?>
<!--Layout Post 1-->
<div class="row">
<article class="grid-style post small-9 small-centered column" id="post-<?php the_ID(); ?>">
<div class="post-img">
<?php get_template_part( 'inc/postformats/grid-style' ); ?>
</div>
<div class="post-box">
<div class="post-title">
<h2><?php echo ShortenText(get_the_title(), 50); ?>1</h2>
</div>
<aside class="post_categories">
<?php the_category(', '); ?>
</aside>
<div class="post-content">
<?php echo ShortenText(get_the_excerpt(), 170); ?>
</div>
</div>
</article>
</div>
<!--/Layout Post 1-->
<?php } ?>
<!--Other Posts -->
<div class="row">
<article class="grid-style post small-9 small-centered column" id="post-<?php the_ID(); ?>">
<div class="post-img">
<?php get_template_part( 'inc/postformats/grid-style' ); ?>
</div>
<div class="post-box">
<div class="post-title">
<h2><?php echo ShortenText(get_the_title(), 50); ?></h2>
</div>
<aside class="post_categories">
<?php the_category(', '); ?>
</aside>
<div class="post-content">
<?php echo ShortenText(get_the_excerpt(), 170); ?>
</div>
</div>
</article>
</div>
<!--/Other Posts -->
<?php if (in_array($i + 1, $counter)){ echo '</div>'; } ?>
<?php $i++; endwhile; ?>
<div class="small-12 columns">
<?php theme_pagination($all_posts->max_num_pages, 1, true); ?>
</div>
<?php else : ?>
<p><?php _e( 'Please add posts from your WordPress admin page.', THB_THEME_NAME ); ?></p>
<?php endif; ?>
</section>
</div>
<?php get_footer(); ?>
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.
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
I am attempting to display, outside of the loop, an alternative, shortened post title using custom fields under a set of 8 post featured image thumbnails in a slidesow. I can display the corresponding post's title under these thumbnails with this snippet of code:
<?php $titletext = get_the_title(); echo( $arr[$i]['titletext'] ); ?>
And I can display the custom field within the loop:
<?php $key="short_title"; echo get_post_meta($post->ID, $key, true); ?>
But any combination of the two that I've tried outside of the loop returns nothing or returns "Array" under each thumbnail. The solution feels obvious but it's eluding me. Can someone show me how to do this correctly?
Adding more code for clarification:
<?php if (have_posts()) : while (have_posts()) : the_post();
global $post; ?>
<?php if ( $responsive ) { ?>
<li class="slide">
<?php } else { ?>
<div class="slide">
<?php } ?>
<?php
$width = $responsive ? 560 : 558;
$height = 340;
$small_width = 110;
$small_height = 63;
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,'',$titletext,$titletext,false,'Featured');
$arr[$i]['thumbnail'] = get_thumbnail($small_width,$small_height,'',$titletext,$titletext,false,'Small');
$arr[$i]['titletext'] = $titletext;
$thumb = $thumbnail["thumb"];
print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height ); ?>
<div class="featured-top-shadow"></div>
<div class="featured-bottom-shadow"></div>
<div class="featured-description scrollcustom">
<div class="feat_desc">
<h2 class="featured-title"><?php the_title() ?></h2>
<p> <?php $key="short_title"; echo $shorttitle; ?> <?php the_content(); ?></p>
</div>
</div> <!-- end .description -->
<?php if ( $responsive ) { ?>
</li> <!-- end .slide -->
<?php } else { ?>
</div> <!-- end .slide -->
<?php } ?>
<?php $i++; endwhile; endif; wp_reset_query(); ?>
<?php if ( $responsive ) { ?>
</ul> <!-- end .slides -->
<?php } else { ?>
</div> <!-- end #slides -->
<?php } ?>
</div> <!-- end #featured -->
<div id="controllers" class="clearfix">
<ul>
<?php for ($i = 0; $i < $featured_num; $i++) { ?>
<li>
<div class="controller " >
<a href="#"<?php if ( $i == 0 ) echo ' class="active"'; ?>>
<?php $titletext ?>
<?php print_thumbnail( $arr[$i]['thumbnail']['thumb'], $arr[$i]['thumbnail']["use_timthumb"], $arr[$i]['titletext'], $small_width, $small_height ); ?>
<span class="overlay"></span><br>
<?php echo( $arr[$i]['titletext'] ); ?>
</a>
</div>
</li>
<?php } ?>
You need global $post if you're outside of the loop