Php wordpress help

Discussion in 'PHP' started by RobeDuke, Nov 21, 2009.

  1. #1
    I am writing the following code for making a plugin
    
    <?php
    header("Content-Type: text/css");
    /*
    Plugin Name: Name of the plugin.
    Plugin URI: The page having information related to plugin.
    Version: 0.1
    Description: Your plugin description.
    Author: Your name
    Author URI: Author's website.
    */
    ?>
    <?php
    function box()
    {
    ?><div class="box">
    <p><b>Author:</b> <?php the_author_link(); ?><p>
    <?php echo get_avatar( get_the_author_email(), '50' ); ?>
    <p><?php the_author_description(); ?></p>
    </div>
    <?php
    }
    function style() {
    echo "
    <style>
    <!--
    .avatar{
    float:left;
    background-color: #fff;
    border:1px solid #ccc;
    padding: 4px;
    margin: 0 7px 2px 0;
    display: inline;
    }
    .box{
    color: #666;
    font-weight: normal;
    background: #fff;
    border: 1px solid #ccc;
    padding: 12px;
    margin-bottom:8px;
    }
    -->
    </style>
    ";
    }
    function author_box_ContentFilter($content)
    {
    if (is_single())
    return $content.box().style();
    else
    return $content;
    }
    
    add_filter('the_content', 'author_box_ContentFilter');
    ?>
    
    PHP:
    This code is appending the author info box at the start of post.But i want to add the box a the end of post.I also tried
    {
    if (is_single())
    return box().$content.style();
    else
    return $content;
    }
    
    PHP:
    But this is also not working.
    Seeking for help to append the box at the end of post.
    Thanks in anticipation
     
    RobeDuke, Nov 21, 2009 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The problem is that you are outputting the box directly instead of appending it to the $content
    change it so that the box function returns the box content as a string
     
    JAY6390, Nov 21, 2009 IP
  3. RobeDuke

    RobeDuke Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for your reply.Will you please give me the exact code.What should i write instead of that?I will be thankful to you.:confused:
     
    RobeDuke, Nov 21, 2009 IP
  4. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <?php
    
    /*
    Plugin Name: Name of the plugin.
    Plugin URI: The page having information related to plugin.
    Version: 0.1
    Description: Your plugin description.
    Author: Your name
    Author URI: Author's website.
    */
    
    function box() {
    	$content = '<div class="box">
    <p><b>Author:</b> '.the_author_link().'<p>
    '.get_avatar(get_the_author_email(), '50').'
    <p>'.the_author_description().'</p>
    </div>';
    	return $content;
    }
    function style() {
    	return "
    <style>
    <!--
    .avatar{
    float:left;
    background-color: #fff;
    border:1px solid #ccc;
    padding: 4px;
    margin: 0 7px 2px 0;
    display: inline;
    }
    .box{
    color: #666;
    font-weight: normal;
    background: #fff;
    border: 1px solid #ccc;
    padding: 12px;
    margin-bottom:8px;
    }
    -->
    </style>
    ";
    }
    function author_box_ContentFilter($content) {
    	if (is_single()) return $content.box().style();
    	else  return $content;
    }
    
    add_filter('the_content', 'author_box_ContentFilter');
    
    ?>
    PHP:
    Something like that should work
     
    JAY6390, Nov 24, 2009 IP
    RobeDuke likes this.
  5. RobeDuke

    RobeDuke Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    But jay the problem is,only gravatar is showing.Other template tags are not working e.g the_author_description and the_author_link
     
    RobeDuke, Nov 24, 2009 IP