Making a Php Snippet to Work

Posted in: Newspaper
Post count: 101

Hello Tagdiv,

Few days back I had requested you a code. I had found a code that works as I wish. But I need some guidance in using it along with the theme. The snippet which I got is given below,

<?php $date = date('Y-m-d');

if($date == '2016-01-16'){
    $my_postid = 10;//This is page id or post id
}else{
    $my_postid = 8;//This is page id or post id
}

$content_post = get_post($my_postid);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content; ?>

I used a plugin that can process Php to insert this code but it didn’t worked. Experts are telling that this code will work only if it is implemented in the theme file. I don’t know how to achieve this. Kindly give me some guidance.

I have find one more code that works perfectly and I’m sharing that here. The thing is the contents it grabbed does not look good and they are without the <p> tag. Kindly help me with this.

<?php 
$date = date('y-m-d');

if($date == '16-01-16'){
    $post_id = 8807;//This is page id or post id
}else{
    $post_id = 6039;//This is page id or post id
}

echo get_post_field('post_content', $post_id);

?>

Thanks

Post count: 6600

Hi,

I’m not sure what you need so please provide additional info on this, like where and what you would want to achieve using this code so we can guide to the file in which you would need to add your implementation or you could use a wp hook and place it in theme’s functions.php file: http://screencast.com/t/KZw24u8Whttps://codex.wordpress.org/Plugin_API/Hooks_2.0.x

Hope this helps!
Thanks

Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.