php - How to add content to wordpress loops? -
i've got if statements plugin execute every post.
for now, lets want add "hello world" every post
i've tried quite few things, can't quite seem figure out.
quite simply, in plugin have:
add_filter('the_post','testing'); function testing($content){ echo "hello world"; } obviously i'm doing wrong hello world doesn't how. can point me in right direction please?
here working code on index.php page of theme: http://pastebin.com/xd1ree8w
id' put if statement @ top, within function in plugin, loads every post.
so works on install using in functions.php
i didnt modify get_the_id() parts use object $obj->id
function everypost_func($obj){ echo 'this sort of cool'; if (get_post_meta(get_the_id(), 'other-link', true)) { $url = get_post_meta(get_the_id(), 'other-link', true); $status = 200; $price = null; //echo "looks you've got other-link selected"; } elseif (get_post_meta(get_the_id(), 'generic-asin', true)) { $status = 100; $asin = get_post_meta(get_the_id(), 'generic-asin', true); //echo "looks you've got generic-asin"; if($_cookie['countrycode'] == "gb") { $reg = "co.uk"; //echo "and we've detected you're in uk <br>"; } else { $reg = "com"; //echo "and we've detected you're not uk <br>"; } } else { if(($_cookie['countrycode'] == "gb") && get_post_meta(get_the_id(), 'link-uk', true)) { $asin = get_post_meta(get_the_id(), 'link-uk', true); $reg = "co.uk"; $status = 100; //echo "looks you're in uk, , have uk link<br>"; } elseif (get_post_meta(get_the_id(), 'link-us', true)) { $asin = get_post_meta(get_the_id(), 'link-us', true); $reg = "com"; $status = 100; //echo "looks you're not in uk, have link you<br>"; } elseif (get_post_meta(get_the_id(), 'link-uk', true)) { $asin = get_post_meta(get_the_id(), 'link-uk', true); $reg = "co.uk"; $status = 100; //echo "looks you're not uk, have uk link<br>"; } else { $status = 404; //echo "looks nothing here you<br>"; } } if($status == 100) { $results = get_aws_details($reg, $asin); $price = $results[0][0]; $url = $results[1][0]; $wishlist = $results[2][0]; //echo "success"; } elseif($status == 404) { $price = null; $url = get_the_permalink(); $wishlist = null; //echo "404"; } } add_action('the_post','everypost_func'); so taking in consideration doing in plugin depend on context constructing it.
example in oop : add_action('the_post',array($this,'everypost_func'));
maybe try make work within theme file ie functions.php if works expecting move in plugin surrounded goodies necessary.
-- will update more upon op commentary
Comments
Post a Comment