How To Limit Words and Characters in content WordPress


How To Limit Words and Characters in content WordPress

1. Words Length:

Remove  the <?php the_content();?>  insert the below code

 <?php $content = get_the_content();
  $trimmed_content = wp_trim_words( $content, 60, '<a href="'. get_permalink() .'">...[ read more ]</a>' ); ?>
  <p><?php echo $trimmed_content; ?></p>
(Change the 60 to your desire words length)

 2. Character Length :

Remove  the <?php the_content();?>  insert the below code

<?php echo substr(strip_tags($post->post_content), 0, 46);?>
//(Change the 46 to your desire string length)

How to get custom values outside Loop


 How to get custom values outside Loop

<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'Your-Custom-Field', true);
wp_reset_query();
?>

Example:

<?php 
global $wp_query;
$postid = $wp_query->post->ID;
$img = get_post_meta($postid, 'sidebar_image', true);
if($img)
{
echo "<img src ='$img'>";
}
else{
?>
<img src="<?php bloginfo("template_url")?>/images/care.jpg" />
<?php
}
wp_reset_query();
?>

How to Get the Dynamic Categories related Posts


How to  Get the Dyanmic Categories:

Here small snippet code is avialble for get categories related  posts

1. You have to give the page name and category name should be same

2. Add below code where you want..and than refresh page . you will get the post related categories.

<?php query_posts('category_name='.get_permalink().'&post_status=publish,future');?>

Function Reference – Content url


The content_url template tag retrieves the url to the content area for the current site with the appropriate protocol, ‘https’ if is_ssl() and ‘http’ otherwise.

WordPress Directories:
home_url() Home URL http://www.example.com
site_url() Site directory URL http://www.example.com or http://www.example.com/wordpress
admin_url() Admin directory URL http://www.example.com/wp-admin
includes_url() Includes directory URL http://www.example.com/wp-includes
content_url() Content directory URL http://www.example.com/wp-content
plugins_url() Plugins directory URL http://www.example.com/wp-content/plugins
theme_url() Themes directory URL
http://www.example.com/wp-content/themes
wp_upload_dir() Upload directory URL
http://www.example.com/wp-content/uploads