Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I use a plugin called WP original Source.

It lets me add the URL of the original article source, which is handy as it credits the original source of article extracts and summaries that I publish of my website.

This URL is then published as metadata in the source code of my webpage, such as:

<meta name="original-source" content="http://www.abc.com.au/article.html">

However, I also want to publish this URL at the bottom of the article extract itself, so that users who read the article extract and want more information, can click the link and get taken to the original full article.

I can't work out how to do this however, being only a novice at php.

I did manage to code the following, however instead of getting the URLs, I get the word "array"

$originalsource = get_post_meta(get_the_ID(), '_original_source', true);
echo $originalsource;

Can someone help me work out what php code I need to insert into the single.php form for the URL of the original source to be published as a visible URL, as well as the metadata statement?

share|improve this question
add comment

2 Answers

get_post_meta is returning an array. Apparently, the plugin is saving _original_source as an array.

I don't know what that array looks like but instead of echo do print_r($original_source); and you get something that looks like:

Array
(
    [a] => apple
    [b] => banana
)

You can then do something like echo $original_source['a'] to print "apple".

share|improve this answer
    
Thanks, but as a real novice I am not sure I understand exactly what needs to be placed there.. Can you type out the complete argument I need to use? –  Robert May 10 '13 at 2:53
    
Just replace echo $original_source; in you code with print_r($original_source); and post the result into your question. –  s_ha_dum May 10 '13 at 2:54
    
Wow, you have given me my first real progress in about a days worth of trying.Thank you! This is what has now been published: Array ( [source1] => abc.com.au/article.html ) How can I now get rid of the word "array" & "[source1] =>"? –  Robert May 10 '13 at 3:25
    
Hmm, something is just not working. This is my code: $originalsource = get_post_meta(get_the_ID(), '_original_source', true); print_r($originalsource); $echo ['source1']; I am getting the following result: Array ( [source1] => abc.com.au/article.html) What is wrong with my code? BTW, it seems the echo command is not doing anything. –  Robert May 10 '13 at 3:35
    
You want echo $original_source['source1'] –  s_ha_dum May 10 '13 at 3:49
show 3 more comments

From the plugin’s source code:

global $post;
$meta = get_post_meta($post->ID,'_original_source',TRUE);
$s1 = $meta['source1'];
$s2 = $meta['source2'];
$s3 = $meta['source3'];
$s4 = $meta['source4'];
$s5 = $meta['source5'];

So it saves up to 5 sources, and you can access these by the names source1source5 like this:

if ( $meta = get_post_meta( get_the_ID(), '_original_source', TRUE) )
{
    $counter = 1;
    $sources = array();

    foreach( $meta as $source )
    {
        $url       = esc_url( $source );
        $sources[] = "<a href='$url'>Source $counter</a>";
        $counter  += 1;
    }

    print "<h3>Sources</h3><ul><li>" . join( "</li><li>", $sources ) . "</li></ul>";
}
share|improve this answer
    
Geez, what can I say but a very big thank you. It works perfectly. I really appreciate your assistance. –  Robert May 10 '13 at 5:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.