Connect with us

Tips & Tricks

Calling custom fields for next/previous posts

Custom fields are definitely very useful and are used on many WordPress installs. Today I’m going to show you how to easily get custom fields values outside the loop.

Published

on

With that said, I’d like to say I am using this snippet for a new theme I am building.

I want to pull a custom field from the “next” & “previous” post. So I used the following to do so:

<?php
  $previous_post = get_previous_post();
  $next_post = get_next_post();
  $image_prev = get_post_meta( $previous_post->ID, 'image', $single = true);
  $image_next = get_post_meta( $next_post->ID, 'image', $single = true);
?>

Simple. This is how I put it to use:

<?php if ( $image_prev != '' ) : ?>

  <img src="<?php echo FROSTY_SCRIPTS  ?>/thumb.php?src=<?php echo $image_prev; ?>&amp;h=50&amp;w=169&amp;zc=1&amp;q=80" alt="" />

<?php endif; ?>
Continue Reading
1 Comment

1 Comment

  1. eylültoprak

    July 7, 2009 at 5:13 pm

    Well, depending on how you can file attachments.
    .-= eylültoprak´s last blog ..al senin olsun… =-.

You must be logged in to post a comment Login

Tips & Tricks

Display custom url if comment authors url is blank

Published

on

Here is a nifty trick for your comments.php template. If someone comes to your site and leaves a comment but doesn’t leave a url back to there site, the default link that is shown in place of the php code comment_author_url is the current page link.

That might not look good. So, here is a little trick that I just implemented into my site. Besides installing the twittar plugin and pulling Twitter avatars I wanted to use the image itself for the authors url like. But if the author doesn’t have a Twitter avatar or a Gravatar it will display a default Gravatar that I set. If the default Gravatar is shown, usually the author will not leave a url link.

I would like to link the image to Gravatar.com so that they can get an image attached to their email address. So.. here is the code:

<?php if($comment->comment_author_url != "") { ?>
<a href="<?php comment_author_url(); ?>"><?php gravatar(); ?></a>
<?php } else { ?>
<a rel="nofollow" href="http://gravatar.com" title="Get a Gravatar today!"><?php gravatar(); ?></a>
<?php } ?>
Continue Reading

Tips & Tricks

Echo custom fields in any category

Published

on

Here is a neat trick. Say you want to show a custom field in you post or in a certain categories post. There is a simple code you need to write in order to accomplish this:

<?php $image = get_post_meta($post->ID, "image", $single = true); ?>
<?php if($image != '') : if(in_category(7)) { echo ''; } else { ?>
<img src="<?php echo $image ?>" alt="<?php the_title(); ?>" /></a>

In the example above I am calling the variable $image and telling the server that it equals the value of “image” inside get_post_meta or “custom field” of the current post.

Then we are asking if that variable $image doesn’t equal nothing or != and if it is in the category id of 7, echo what ever is in the single quotes (which is nothing in this example), otherwise show the <img> and the value inside “image” which should be the location of the image.

Update: Thanks to Austin from PressedWords for pointing out his trick, from the comment below.

Continue Reading

Tips & Tricks

Disable caching of your site or post

Published

on

I talked about Disabling search engine on search pages in a previous post using the meta tag. Today lets go over the web bots Cached copy of your site. If you are working on builder your blog, or have a temporary site up, use the following code:

<meta name="robots" content="noarchive">

This will tell any bot to follow your site, index it, but prevents a cached copy of this page from being available in the search results.

Continue Reading

Random Search Terms

Title

Top Articles

Top Searches

powered by WassUp

Recent Posts: Fully Net Worth . com

Bandhunta Izzy Net Worth: How Rich is the Rapper in 2019?

Bandhunta Izzy Net Worth: How Rich is the Rapper in 2019?

Israel Jordan James, who is better known by his stage name as Bandhunta Izzy, is an American rapper who is best known for songs such as “BBB,” “Rumors” and “I Got It”. The young rapper is currently signed with Universal Republic Records. As of 2019, Bandhunta Izzy net worth is estimated to be $700,000. James […]

Teejayx6 Net Worth: How Rich is the Rapper Teejayx6 Actually?

Teejayx6 Net Worth: How Rich is the Rapper Teejayx6 Actually?

Teejayx6 is an emerging American rapper who has recently become a viral sensation for his scam-based songs about identity theft and credit card fraud. The song that was a big success and conveyed this message was called “Dark Web”. As of 2019, Teejayx6 net worth is estimated to be $250,000. He has never revealed his […]

Jade Cline Net Worth: How Rich is the Teen Mom star Actually?

Jade Cline Net Worth: How Rich is the Teen Mom star Actually?

Jade Cline is a TV personality who is best known for being a part of different MTV shows including “Teen Mom” and the “Young and Pregnant”. She replaced Jenelle Evans in the second half of Season 9 of Teen Mom 2. As of 2019, Jade Cline net worth is estimated to be $150,000. Jade was […]

Trending

%d bloggers like this: