Connect with us

Articles

Echo Images inside a Post into the Loop

Published

on

Here is a useful trick. Want to call or echo an image into your blog post with our using the custom fields? Well this could be tricky, but I know of a way.

All you have to do is print these lines of code into your
index.php or home.php inside the loop:

<?php
$id =$post->ID;
$the_content =$wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = $id");
$home = get_option('home');
$pattern = '!<img.*?src="'.$home.'(.*?)"!';
preg_match_all($pattern, $the_content, $matches);
$image_src = $matches['1'][0]; ?>

then after write:

<?php if($image_src != '') { ?>
<a href="<?php echo the_permalink() ?>" rel="bookmark" title="Link to <?php the_title(); ?>"><?php the_title(); ?></a><br />
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php echo $image_src; ?>" alt="<?php the_title(); ?>" /></a>
<?php }  ?>

That’s all! This will look for the first image in your post and echo it in the loop, could be used to show off those pretty thumbnails for the post..

Continue Reading
7 Comments

7 Comments

  1. Austin

    December 8, 2008 at 3:54 am

    Assuming the image has been added using the WP uploader, here’s a way of doing the same thing using the WP API, which might have a performance advantage:

    <?php $attachments = (array) get_children(array(‘post_parent’ => get_the_ID(), ‘post_type’ => ‘attachment’));
    if ( ! empty( $attachments ) ) :
    $attmt = array_shift($attachments);
    $image_thumb = wp_get_attachment_thumb_url($attmt->ID); ?>
    <a href=”<?php echo the_permalink() ?>” rel=”bookmark” title=”Link to <?php the_title(); ?>”><?php the_title(); ?></a><br />
    <a href=”<?php the_permalink() ?>” rel=”bookmark” title=”<?php the_title(); ?>”><img src=”<?php echo $image_thumb; ?>” alt=”<?php the_title(); ?>” /></a>
    <?php endif; ?>

  2. frosty

    December 8, 2008 at 10:59 am

    Thanks for that one!

  3. Picsbuzz

    January 7, 2009 at 9:57 pm

    This is great script, it helps me a lots!!! Thank you so much!!
    I wonder if this script can grab the first image in the post which hosted on share host like: flickr or imagesharkus?

    • frosty

      January 7, 2009 at 10:05 pm

      Your welcome, I am not sure. If we could find out details to their database it may be possible.

  4. Nick

    January 15, 2009 at 12:38 pm

    That can be useful

    Nick’s last blog post..Montana Library

  5. Thomas

    August 10, 2009 at 11:00 am

    Hi all,
    First of all, very nice script. I noticed that the output was in html (ie, img src and thumbnailing).
    Does anyone know of any snippet to be able to echo the image via php, without having to name the actual individual image file (eg. tree.jpg), and instead using a variable from a database that names photos in a directory.?
    thanks
    tom

  6. Maor

    September 5, 2009 at 5:33 pm

You must be logged in to post a comment Login

Leave a Reply

Articles

The launch of WordPress.tv

Published

on

Hey, in case you are unaware, WordPress has launched a new site called WordPress.tv. Check out the full post at the WordPress.org blog. Or visit WordPress.tv

…WordPress.tv is also now the place to find all that awesome WordCamp footage that was floating around the web without a home. See the presentations you missed and get a peek at behind-the-scenes action. We call it WordCampTV.

You’ll also find slideshows of presentations made by Automattic employees and other WordPress gurus, plus interviews I’ve done with the media and fellow bloggers….

Continue Reading

Guest Post

10 Steps to Evaluating and Measuring Your Marketing Strategy

Published

on

10 Steps to Evaluating and Measuring Your Marketing Strategy 7

10 Steps to Evaluating and Measuring Your Marketing Strategy 8

When you are trying to market a product, the product or service is only as good as the potential clientele think it is. You need to get them to buy or use the item or service before you can tell if it really works for them. How can you go about evaluating and measuring your current marketing strategy?
Input vs. Output
Check your financial statements. Are you spending more money than you are making? In a strong marketing campaign, this should not be the case. You want to tweak your plan to make more money than you are putting into the project.
Customer Surveys
When you sell a product, include a survey along with it. Ask the customer to rate different qualities of the product that directly relate to the market. For example, ask them how they heard about the product and if the visual appeal of the item had anything to do with its purchase.
Phone Surveys
Distribute flyers, pamphlets and other coupon offers to people and see if they call back. You’ll know if the marketing works based upon how many people call. When they do call, ask what elements of the flyer or other item made them want to call you.
Test Group
Before you send a new item onto the market, have a test group to evaluate your marketing. For example, you might bring in a section of the company that has never seen the ad. Ask them what they think and if they would buy the product.
Introspective Analysis
What about you? Try to separate yourself from the ad as much as possible. Imagine that you were walking down the street and saw this advertisement. Would you feel inclined to purchase it or use the service? What elements of it are captivating and visually appealing? What elements turn you away?
Quantitative Data
Of course, all of these surveys and questions are important; however, you must generate quantitative data from all of them. For example, calculate the percentage of people who learned about your company from the Internet, paper flyers, word of mouth, and so forth. Put the information into charts.
Compare Years
After you have put the information into charts, you should start comparing this year’s findings to last year’s findings. If you find that a larger percentage of people are using the Internet than last year, you will have gained valuable insight into the company’s advertising.
Targeting the Many…
Once you find where most of your patrons are coming from, work to keep up steady advertisements in that domain. If most people are finding your company through Google searches, maintain fresh SEO strategies throughout the year to keep generating customers in that manner.
…And the Few
Let’s say that very few people are finding you from paper advertisements in the local department store. If this is a new trend, give it another shot to try to keep those few customers that you have. If it’s a continuing trend, you may want to put that money into another avenue.
Keep It Up
Don’t let your evaluation and measuring strategies fall to the wayside. You need to keep using them to ensure constant success for your company.
Evaluation and measurement strategies can bring both good and bad news to you about your marketing strategy. Be sure to use all of the information to generate more positive outcomes.

Thaddeus McGregor writes about business, marketing & finance at

www.businessinsurance.org.

Continue Reading

Tips & Tricks

Can′t add pagination on WooThemes Thick Theme

Published

on

Everything I have tried has led to nothing. And I have tried six way’s from Sunday to get my main posts to paginate.

example one:

<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
query_posts('offset=1&showposts=' . get_option('woo_other_entries') . '&cat=-' . $GLOBALS['ex_asides'] . '&paged=$paged' ); ?>

example two:

<?php 
global $myOffset; 
global $wp_query;
$myOffset = 1;
$paged = intval(get_query_var('paged')) ? get_query_var('paged') : 1;
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query(array(
	'offset' => $myOffset,
	'category__not_in' => array($GLOBALS['ex_asides'],7,84),
	'paged' => $paged,
	'showposts' => get_option('woo_other_entries'),
	)); ?>

example three:

<?php 
global $myOffset;
$myOffset = 1;
$wp_query = new WP_Query();
$wp_query->query(array(
	'offset' => $myOffset,
	'category__not_in' => array($GLOBALS['ex_asides'],7,84),
	'paged' => $paged,
	'showposts' => get_option('woo_other_entries'),
	)); ?>

And after those tries, I just can’t get more pages beyond the option’s that I choose, and can only pull an archive via the browse more link.

Any suggestions or anything?

Continue Reading

Trending