Powered By Blogger
Showing posts with label blog. Show all posts
Showing posts with label blog. Show all posts

Friday, October 14, 2016

get post author info in single.php in wordpress


http://www.wpbeginner.com/wp-tutorials/how-to-add-an-author-info-box-in-wordpress-posts/



Function.php

/**
 * Add authour info in post view
 */

function wpb_author_info_box( $content ) {

global $post;

// Detect if it is a single post with a post author
if ( is_single() && isset( $post->post_author ) ) {

// Get author's display name
$display_name = get_the_author_meta( 'display_name', $post->post_author );

// If display name is not available then use nickname as display name
if ( empty( $display_name ) )
$display_name = get_the_author_meta( 'nickname', $post->post_author );

// Get author's biographical information or description
$user_description = get_the_author_meta( 'user_description', $post->post_author );

// Get author's website URL
$user_website = get_the_author_meta('url', $post->post_author);

// Get link to the author archive page
$user_posts = get_author_posts_url( get_the_author_meta( 'ID' , $post->post_author));

if ( ! empty( $display_name ) )

$author_details = '<p class="author_name">About ' . $display_name . '</p>';

if ( ! empty( $user_description ) )
// Author avatar and bio

$author_details .= '<p class="author_details">' . get_avatar( get_the_author_meta('user_email') , 90 ) . nl2br( $user_description ). '</p>';

$author_details .= '<p class="author_links"><a href="'. $user_posts .'">View all posts by ' . $display_name . '</a>';

// Check if author has a website in their profile
if ( ! empty( $user_website ) ) {

// Display author website link
$author_details .= ' | <a href="' . $user_website .'" target="_blank" rel="nofollow">Website</a></p>';

} else {
// if there is no author website then just close the paragraph
$author_details .= '</p>';
}

// Pass all this info to post content
$content = $content . '<footer class="author_bio_section" >' . $author_details . '</footer>';
}
return $content;
}

// Add our function to the post content filter
add_action( 'the_content', 'wpb_author_info_box' );

// Allow HTML in author bio section
remove_filter('pre_user_description', 'wp_filter_kses');

Tuesday, September 27, 2016

wordpress get latest post from another website

1.Using Template
2. RSS widget


https://www.worldoweb.co.uk/2012/display-wordpress-posts-on-another-wp-blog

plugin:

https://wordpress.org/plugins/featured-images-for-rss-feeds/screenshots/

https://wordpress.org/plugins/wp-rss-aggregator/screenshots/



<?php
/**
 * Template Name: Blog  Page
 *
 * A Fully Operational maintenance Page
 *  WordPress
 */

get_header(); ?>
<div class="content_bgr website-maintenance-plan websiteplan-plan">
<div class="full_container_page_title">
<div class="container startNow">
<div class="row no_bm">
<?php
//replace with your URL
$rss = fetch_feed("http://demoinfolink.com/blog/");

if (!is_wp_error($rss)) :

$maxitems = $rss -> get_item_quantity(5); //gets latest 5 items This can be changed to suit your requirements
$rss_items = $rss -> get_items(0, $maxitems);
endif;

//grabs our post thumbnail image
function get_first_image_url($html) {
if (preg_match('/<img.+?src="(.+?)"/', $html, $matches)) {
return $matches[1];
}
}

//shortens description
function shorten($string, $length) {
$suffix = '&hellip;';
$short_desc = trim(str_replace(array("\r", "\n", "\t"), ' ', strip_tags($string)));
$desc = trim(substr($short_desc, 0, $length));
$lastchar = substr($desc, -1, 1);
if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?')
$suffix = '';
$desc .= $suffix;
return $desc;
}
?>
<!--start of displaying our feeds-->
<ul class="rss-items" id="wow-feed">
<?php
if ($maxitems == 0) echo '<li>No items.</li>';
else foreach ( $rss_items as $item ) :
?>
<li class="item">
<span class="rss-image">
<?php echo '<img width="200" src="' . get_first_image_url($item -> get_content()) . '"/>'; ?>
</span>
<span class="data">
<h5><a href='<?php echo esc_url($item -> get_permalink()); ?>' title='<?php echo esc_html($item -> get_title()); ?>'> <?php echo esc_html($item -> get_title()); ?></a></h5>
<span class="date-image">&nbsp;</span>
<small><?php echo $item -> get_date('F Y'); ?></small><!--This can be changed -->
<span class="comment-image">&nbsp;</spa






































































n>







































































<small><?php $comments = $item -> get_item_tags('http://purl.org/rss/1.0/modules/slash/', 'comments'); ?><?php $number = $comments[0]['data']; ?>
<?php //checks and displays comment count
if ($number == '1')
{
echo $number . "&nbsp;" . "Comment";
}
else


























































{


























































echo $number . "&nbsp;" . "Comments";
}
?>
</small>
<p><?php echo shorten($item -> get_description(), '150'); ?></p>
</span>






































</li>






































<?php endforeach; ?>
</ul>

</div>
</div>
</div>
</div>

<?php get_footer(); ?>








add the following to your theme’sfunctions.php

Whilst functions.php is open check for or add the following