wordpress get post thumbnail outside wordpress - wordpress

This is my link.php script for show latest title and tumbnail from my wordpress site. Title working fine thumbnail not work. it only show mysite/wp-includes/images/media/default.png, But my content have uloaded image. How can i get thumbnail image
<?php
require('../../wp-blog-header.php');
?>
<?php
$posts = get_posts('numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) : setup_postdata( $post ); ?>
<?php get_the_ID(); echo "<br />"; ?>
<?php the_title(); ?> <?php echo "<br />"; ?>
<?php
$imgId = get_post_thumbnail_id($post->ID);
$imgUrl = wp_get_attachment_image_src($imgId,'thumbnail', true);
?>
<img src="<?php echo $imgUrl[0]; ?>" />
<?php
endforeach;
?>

In wordpress use the inbuilt function for including files so:
<?php get_header(); ?> - Providing header.php exists it will bring it in.
<?php $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 2600,1000 ), false, '' );?>
<div class="front-page-post-img" style="background: url(<?php echo $src[0]; ?> ); background-size: cover; background-repeat:no-repeat;"></div>
<?php if(is_single()): ?>
<?php the_content(); ?>
<?php comments_template(); ?>
<?php else: ?>
<?php echo substr(get_the_excerpt(), 0,45); ?>
<a class="post-link" href="<?php the_permalink(); ?>">more...</a>
<?php endif; ?>

Related

WordPress posts are not showing at all

I have tried several codes to display WordPress posts in my theme I create but nothing works - why?
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
<div class="entry">
<?php the_content(); ?>
</div>
<div class="postmetadata">
<?php the_tags('Tags: ', ', ', '<br />'); ?>
Posted in <?php the_category(', ') ?> |
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
</div>
</div>
<?php endwhile; ?>
<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
<?php
if (have_posts()) :
while (have_posts()) :
the_post();
the_content();
endwhile;
endif; ?>
Nothing is showing the posts why? I have the following files in my theme: index.php, header.php, style.css, footer.php, page.php, single.php
<?php
query_posts(array(
'post_type' => 'YOUR_POST_TYPE_NAME', // Add your post-type name
'showposts' => 10
) );
?>
Please add this code in your above If statement.
<?php
$args = array(
'post_type' => 'post',
'post_status'=>'publish'
);
$wpquery = new WP_Query($args);
if ($wpquery->have_posts()) : while ($wpquery->have_posts()) : $wpquery->the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
<div class="entry">
<?php the_content(); ?>
</div>
<div class="postmetadata">
<?php the_tags('Tags: ', ', ', '<br />'); ?>
Posted in <?php the_category(', ') ?> |
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
</div>
</div>
<?php endwhile; ?>
<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
<?php
if ($wpquery->have_posts()) :
while ($wpquery->have_posts()) :
the_post();
the_content();
endwhile;
endif; ?>

how to display each gallery image in category page

i want to make categories gallery. so i have one category called gallery, i create some post with gallery images. in gallery category page i want to display each post 4 picture. picture will take from advancedcustomfields gallery field. bellow is my current category-gallery page code, image not coming but title and more link working fine. would guys tell me what how to do ?
<?php get_header(); ?>
<div class="contentarea">
<div class="wapper">
<div class="content clearfix">
<?php
while ( have_posts() ) :
the_post();
$images = get_field('gallery_picture');
?>
<h2><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></h2>
<img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" /> Gallery </div>
<?php endwhile; ?>
</div>
</div>
</div>
<?php get_footer(); ?>
i solve this problem. so want to share with other. this for category page. bellow is code
<?php
while ( have_posts() ) :
the_post();
?>
<h2><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></h2>
<?php
$images = get_field('gallery_picture');
$max = 5;
$i = 0;
if( $images ): ?>
<ul>
<?php foreach( $images as $image ): $i++; ?>
<?php if( $i > $max){ break; } ?>
<li> <img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" /> </li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Gallery </div>
<?php endwhile; ?>

WordPress sticky post not showing

In my Index.php template file I have the following code which should show a featured post if it's sticky and then loop through the remaining posts below. However on the second loop shows anything and the sticky post does not appear...
The post has definitely been made sticky and second loop has successfully hidden it but the first loop just doesn't acknowledge it :/ it's not set to private and is marked as published.
Can anyone see any issues with the code? Thanks
<?php get_header(); ?>
<div class="clearfix">
<?php if(is_home()) { //if home then show the featured post and others ?>
<div class="main-column">
<?php
$sticky = get_option( 'sticky_posts' );
$sticky_query = new WP_Query( 'p=' . $sticky[0] );
// The Loop
while ( $sticky_query->have_posts() ) : $sticky_query->the_post(); ?>
<div class="featured">
<article class="clearfix">
<h2><?php echo $post->post_title ?></h2>
<p class="who-when">by <?php echo get_the_author_meta('first_name'); ?> <?php echo get_the_author_meta('last_name') ?> on <?php echo get_the_date() ?> </p>
<?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
echo '<a href="'.get_permalink().'">';
the_post_thumbnail();
echo '</a>';
} else {
echo '<img src="'. get_bloginfo('template_directory') .'/images/thumb-placeholder.png" alt="Blog thumbnail" />';
}?>
<p><?php the_excerpt_max_charlength(300) ?></p>
</article>
</div>
<?php endwhile; ?>
<div class="articles">
<?php $query = new WP_Query( array( 'post__not_in' => get_option( 'sticky_posts' ), 'posts_per_page' => 10 ) );
$count = 0;
while ( $query->have_posts() ) : $query->the_post();
$count++; ?>
<div <?php if($count % 2 == 0) echo 'class="no-margin"' ?>>
<article>
<h2><?php echo $post->post_title ?></h2>
<p class="who-when">by <?php echo get_the_author_meta('first_name'); ?> <?php echo get_the_author_meta('last_name') ?> on <?php echo get_the_date() ?> </p>
<?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
echo '<a href="'.get_permalink().'">';
the_post_thumbnail();
echo '</a>';
} else {
echo '<img src="'. get_bloginfo('template_directory') .'/images/thumb-placeholder.png" alt="Blog thumbnail" />';
}?>
<p><?php the_excerpt_max_charlength(150) ?></p>
</article>
</div>
<?php if($count % 2 == 0) echo '<hr/>' ?>
<?php endwhile; ?>
</div>
<?php }else if(is_search() || is_category || is_tag()){ //if other than home (search, tag, category) then show normal list (no featured style) ?>
<div class="main-column search">
<?php
$count = 0;
if(is_search()){
echo '<h1>Search Results</h1>';
} elseif(is_author()){ ?>
<?php $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author)); ?>
<h1><?php echo $curauth->user_firstname; ?> <?php echo $curauth->user_lastname; ?></h1>
<div class="archive-meta">
<p><?php echo $curauth->user_description; ?></p>
</div>
<?php } else if(is_category()){ ?>
<h1><?php single_cat_title( '', true ); ?></h1>
<?php
$category_description = category_description();
if ( ! empty( $category_description ) )
echo '<div class="archive-meta">' . $category_description . '</div>';
?>
<?php }else if (is_tag()){
echo '<h1>'.the_tag().'</h1>';
}
if ( have_posts() ) : while ( have_posts() ) : the_post();
$count++; ?>
<div>
<article>
<h2><?php echo $post->post_title ?></h2>
<p class="who-when">by <?php echo get_the_author_meta('first_name'); ?> <?php echo get_the_author_meta('last_name') ?> on <?php echo get_the_date() ?> </p>
<?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
echo '<a href="'.get_permalink().'">';
the_post_thumbnail();
echo '</a>';
} else {
echo '<img src="'. get_bloginfo('template_directory') .'/images/thumb-placeholder.png" alt="Blog thumbnail" />';
}?>
<p><?php the_excerpt_max_charlength(300) ?></p>
</article>
</div>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
<?php } ?>
</div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
Changing the code to:
$sticky_query = new WP_Query( 'p=' . $sticky[1] );
fixes the problem but I don't know why???

more flexible or advanced page creation in wordpress 3.2.1

I've been looking into ways to make the wordpress page creation be a little more flexible.
I've gotten as far as defining my own template pages and using those to create the new pages, but I'd like to be able to have a way to input content for more than just the one post div.
When creating a page it is similar to creating a post - i.e you get to edit a title and a bit of content but that's it.
Does anyone know of a method or plugin that would allow editing the title and content of 2 divs on the same page during page creation?
I suggest you use Magic Fields. It basically allows you to add a lot of custom fields. It allows you to build advanced templates. Example of one I created recently:
<?php get_header();?> <div id="left_sidebar" class="grid_3">
<ul class="post_menu sf-menu sf-vertical">
<li class="active"><?php echo $post->post_title; ?></li>
<?php $currentPost = $post; ?>
<!-- Start Loop -->
<?php $args=array(
'post_type' => "post",
'category__in' => get_page_cats($post->ID),
'showposts' => '5000',
'order_by' => 'date',
'order' => 'ASC');
?>
<?php $menu_posts = array(); ?>
<?php $the_query = new WP_Query( $args );?>
<?php if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?>
<?php if($related_content = get('menu_parent_page')): ?>
<?php $menu_posts[$related_content]['sub'][] = array('id' => $post->ID, 'title' => $post->post_title); ?>
<?php else: ?>
<?php $menu_posts[$post->ID]['parent'] = array('id' => $post->ID, 'title' => $post->post_title); ?>
<?php endif; ?>
<?php endwhile; else: ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
<?php $postCount = 1; ?>
<?php $totalPosts = sizeof($menu_posts); ?>
<?php if($totalPosts > 0):?>
<?php foreach($menu_posts as $the_post): ?>
<li <?php if($postCount == $totalPosts): ?> class="last<?php if($currentPost->ID == $the_post['parent']['id']): ?> active<?php endif; ?>"<?php elseif($currentPost->ID == $the_post['parent']['id']): ?> class="active"<?php endif; ?> ><?php echo $the_post['parent']['title']; ?>
<?php $totalSubPosts = sizeof($the_post['sub']); ?>
<?php $subPostCount = 1; ?>
<?php if($totalSubPosts > 0):?>
<ul>
<?php foreach($the_post['sub'] as $sub_post): ?>
<li <?php if($subPostCount == $totalSubPosts): ?> class="last" <?php endif; ?>><?php echo $sub_post['title']; ?>
<?php $subPostCount++; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php $postCount++; ?>
<?php endforeach; ?>
<?php endif; ?>
</ul>
</div>
<div id="page_content" class="grid_9">
<!-- Start Loop -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1 class="page_header"><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php $logo_image = get_image('extra_logo_image', 1, 1, 0); ?>
<?php if($logo_image): ?>
<img class="brand_logo_all" src="<?php echo $logo_image; ?>" alt="logo" />
<?php endif; ?>
<?php endwhile; else: ?>
<p>An Error Occurred</p>
<?php endif; ?>
<?php wp_reset_query(); ?>
<!-- End Loop -->
<?php $download_items = get_group('download'); ?>
<?php if($download_items): foreach ($download_items as $item): ?>
<div class="download">
<a href="<?php echo $item['download_pdf'][1];?>">
<div class="pdf">
<table>
<tr>
<td><?php echo $item['download_description'][1];?></td>
</tr>
</table>
</div>
</a>
</div>
<?php endforeach; endif;?>
<?php $disable_call_to_action = get('extra_disable_call_to_action'); ?>
<?php if(!$disable_call_to_action): ?>
<?php include_once(TEMPLATEPATH . "/call_to_action.php"); ?>
<?php endif; ?>
</div><!-- #page_content -->
</div><!-- #container --><?php get_footer();?>

How do I set ACF repeater to only show X items per row

I'm using ACF pro repeater fields, which renders individual images per row. However it shows all images until it wraps to the next line:
<div class="client-logo-web-wrapper"><?php $logo_images = get_field( 'logo' ); ?>
<?php if ( $logo_images ) : ?>
<?php foreach ( $logo_images as $logo_image ): ?>
<a href="<?php echo $logo_image['url']; ?>">
<img src="<?php echo $logo_image['sizes']['thumbnail']; ?>" alt="<?php echo $logo_image['alt']; ?>" />
</a>
<p><?php echo $logo_image['caption']; ?></p>
<?php endforeach; ?>
<?php endif; ?>
<?php if ( have_rows( 'logo_gallery' ) ) : ?>
<?php while ( have_rows( 'logo_gallery' ) ) : the_row(); ?>
<?php $client_logo = get_sub_field( 'client_logo' ); ?>
<?php if ( $client_logo ) { ?>
<div class="client-logo"><img src="<?php echo $client_logo['url']; ?>" alt="<?php echo $client_logo['alt']; ?>" />
</div>
<?php } ?>
<?php endwhile; ?></div>
<?php else : ?>
<?php // no rows found ?>
<?php endif; ?>
Instead I would like to display a set number of images (for ex. 4) per row. Thanks!
You need to define the limit, and the break the loop once you reach that limit. Also, you can also set the max number of items in your ACF field definition.
Try the following with the limit set:
<?php
$show = 4;
$count = 0;
?>
<?php if ( $logo_images ) : ?>
<?php foreach ( $logo_images as $logo_image ): ?>
<?php $count++; ?>
<a href="<?php echo $logo_image['url']; ?>">
<img src="<?php echo $logo_image['sizes']['thumbnail']; ?>" alt="<?php echo $logo_image['alt']; ?>" />
</a>
<p><?php echo $logo_image['caption']; ?></p>
<?php if ($count > $show) { break; } ?>
<?php endforeach; ?>
<?php endif; ?>

Resources