Showing posts with label wordpress post ancestors. Show all posts
Showing posts with label wordpress post ancestors. Show all posts

Monday, 3 October 2011

How to add custom content to each post automatically?




Many bloggers will have a habit to write custom content after each post. Like “We welcome your suggestions on this blog “ Or something like ask readers to subscribe their RSS feed “If you like this post subscribe to our rss feed”.

We can hard code this content after the post content or we can add it every time when we write a new post. Adding this content every time, when we write a new article is not the right choice.

To automate this one add the following code to your theme functions.php i.e

function addFootNote($content) {
        if(is_feed() || is_single()) {
                $content.= "<div class='subscribes'>";
                $content.= "<h4>like this article?</h4>";
                $content.= "<p>Subscribe to our  <a href='http://feeds2.feedburner.com/wordpressnotes>RSS feed</a> </p>";
                $content.= "</div>";
        }

        return $content;
}

Thursday, 15 September 2011

How to get post ancestors of a post?


In wordpress we have an option to assign a post as a child to another post. In order to get the ancestors of a post wordpress have an inbuilt function i.e.  get_post_ancestors( ).

This function will have one argument that can be either post id or post object and it returns the ancestor’s ids as an array. 

$ancestors=get_post_ancestors($post_id);