DynamicWP » Tutorial http://www.dynamicwp.net Designing Beautiful Wordpress ThemeTue, 01 Jul 2014 06:58:10 +0000en-UShourly1http://wordpress.org/?v=3.9.2How to Hide a Part of WordPress Post or Page from Non-logged in Visitor http://www.dynamicwp.net/articles-and-tutorials/hide-a-part-of-wordpress-post-or-page/ http://www.dynamicwp.net/articles-and-tutorials/hide-a-part-of-wordpress-post-or-page/#commentsMon, 01 Aug 2011 05:44:08 +0000http://www.dynamicwp.net/?p=5417 Related posts:
  1. Exclude Pages or Posts of Certain Categories from WordPress Search Result
  2. How to Create Drop Cap to WordPress Post without Plugin
  3. How to Limit Character in The Post Title
]]>
WordPress provide private feature to make your post or page only visible to other editors or site admin. Once a post is set to private, regular visitor won’t be able to read the post.

Now, what a about if We want to hide only a part of the post? This code snippet will show You how to do it.

First, you need to put the code below to function.php file in your active theme. After that, to hide an element or part in the post, you have to put that part between [hide] and [/hide] tags.

For example: [hide]Hidden paragraph bla bla[/hide]

The Non-logged in visitor now can’t read the text between those two tags

Here’s the code for function.php :

function Wp_UCanHide($text) {
    
	global $user_ID;

        if ($user_ID == '') {

	$posdebut = strpos($text, '[hide]');
	$posfin = strpos($text, '[/hide]');
	$posfin = $posfin + 5;
	       

        $texttohide = substr($text,$posdebut,$posfin);
        $text = str_replace($texttohide, "", $text);        
        
        return $text;

        }else{

        $text = str_replace('[hide]', "", $text);
        $text = str_replace('[/hide]', "", $text);

        return $text;

        }
}

// Apply the filters, to get things going
add_filter('the_content', 'Wp_UCanHide');

Hope this tutorial helps.

Credits:
The code is taken from WP UCanHide plugin, http://wordpress.org/extend/plugins/wp-ucanhide/, with a lithe modification.

]]>
http://www.dynamicwp.net/articles-and-tutorials/hide-a-part-of-wordpress-post-or-page/feed/9
How to Exclude Category from Post’s Category List http://www.dynamicwp.net/articles-and-tutorials/exclude-category-from-posts-category-list/ http://www.dynamicwp.net/articles-and-tutorials/exclude-category-from-posts-category-list/#commentsMon, 25 Jul 2011 02:22:07 +0000http://www.dynamicwp.net/?p=5350 Related posts:
  1. Exclude Pages or Posts of Certain Categories from WordPress Search Result
  2. Create Dropdown List of Posts from a Category
  3. How to List Categories along with Their Posts
]]>
WordPress provides a function that displays the category to which a post belongs: the_category(). If the post is in multiple categories, the function will list them all, linked to the respective archive page.

For some reason, maybe you want to exclude one or two categories for the list. This can be achieved by hacking the_category function, or create a new code to list the category, to replace the_category.

Most of the tutorials I found are using the first, by hacking the_category function. This snippet will do the second one.

<?php
     foreach((get_the_category()) as $category) {
        if ($category->cat_name != 'cat_to_exclude') {
           echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> ';
        }
     }
?>

The code above is to list post’s categories, where category ‘cat_to_exclude’ will be exclude from the list. You can use this code to replace the_category function in your theme.

Hope this snippet helps :)

Our 646-364 exams provide you 100% pass guarantee.You can get access to mcts with multiple prep resources of ccent.

]]>
http://www.dynamicwp.net/articles-and-tutorials/exclude-category-from-posts-category-list/feed/4
How to Remove Links Tab from Admin Panel http://www.dynamicwp.net/articles-and-tutorials/remove-links-tab-from-admin-panel/ http://www.dynamicwp.net/articles-and-tutorials/remove-links-tab-from-admin-panel/#commentsTue, 24 May 2011 09:32:42 +0000http://www.dynamicwp.net/?p=4878 Related posts:
  1. Remove Title Attribute from WordPress Menu Link
  2. How to Add “delete” and “spam” Buttons to Your Comments
  3. How to Order Categories by Most Recently Updated
]]>
WordPress admin interface has became more intuitive now. In the admin page, You can see the main navigation menu detailing each of the administrative functions you can perform, grouped in collapsible tabbed panels on the left-hand side column.

One of the tab is Links tab. This tab is to add a new link, edit existing links or create link categories. Links create in here will be display in the blogroll section of your blog.

Often, people doesn’t use this tab at all, so simplifying the admin panel by removing the tab can be done. To remove the tab, simply put the code below in your theme functions.php file.


add_action( 'admin_init', 'remove_links_tab_menu_pages' );

function remove_links_tab_menu_pages() {
	remove_menu_page('/category/tutorial/feed/link_manager.html');
	remove_menu_page('/category/tutorial/feed/tools.html');	
}

Hope this code helps.

Credit : The code is taken from http://wordpress.org/extend/plugins/remove-links-page

]]>
http://www.dynamicwp.net/articles-and-tutorials/remove-links-tab-from-admin-panel/feed/3
How to Get URL for Blog Page When Using Static Homepage http://www.dynamicwp.net/articles-and-tutorials/url-for-blog-page-when-using-static-omepage/ http://www.dynamicwp.net/articles-and-tutorials/url-for-blog-page-when-using-static-omepage/#commentsTue, 17 May 2011 09:45:59 +0000http://www.dynamicwp.net/?p=4795 Related posts:
  1. Pagination Problem When Excluding Certain Categories from Blog Main Page
  2. How to Create a Stylish Post Title on your Homepage
  3. How to Add New Class to First Post in The Homepage
]]>
By default, a WordPress website displays the blog page, which is your most recent posts, on the front page. But many WordPress users want to have a static front page or splash page as the front page instead. Fortunately, WordPress allows you to select a different page for your home page. You can also create another page that you use as blog page. You can read how to create static homepage: link.

Get URL for Blog Page

Once your WP site has been set up to use a static front page, You maybe need the URL of the page that has been designated as the blog page.

Here’s the code to get the link:

<?php 
$posts_page_id = get_option( 'page_for_posts');
$posts_page = get_page( $posts_page_id);
$posts_page_title = $posts_page->post_title;
$posts_page_url = get_page_uri($posts_page_id  );
?>

$posts_page_url is the url to blog page and $posts_page_title is the page title

Now You can use it in HTML a tag to link to your blog page, for example:

<a href="<?php echo $posts_page_url; ?>" title="<?php echo $posts_page_title; ?>">blog</a>

Hope this post helps

Credit:
Esmi and Tirussell from wordpress.org

]]>
http://www.dynamicwp.net/articles-and-tutorials/url-for-blog-page-when-using-static-omepage/feed/9
How to Display Posts only from Current User http://www.dynamicwp.net/articles-and-tutorials/display-posts-only-from-current-user/ http://www.dynamicwp.net/articles-and-tutorials/display-posts-only-from-current-user/#commentsTue, 10 May 2011 09:04:32 +0000http://www.dynamicwp.net/?p=4723 Related posts:
  1. How to Add “delete” and “spam” Buttons to Your Comments
  2. How to Display your Most Popular Posts with Thumbnails in WordPress
  3. How to Display Most Popular Posts from a Specific Category
]]>
When a contributor in a multi-user site see the post list in the admin page, he could see not only his posts, but also posts from other contributors. Even he couldn’t edit the other posts, this still could be a problem if there’s alot post already and he have to search from page to page to find his posts. How about displaying his post only? This snippet will show how to do it.

User post only

Simply put the code into your theme functions.php.

function mypo_parse_query_useronly( $wp_query ) {
    if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp_admin/edit.html' ) !== false ) {
        if ( !current_user_can( 'level_10' ) ) {
            global $current_user;
            $wp_query->set( 'author', $current_user->id );
        }
    }
}

add_filter('parse_query', 'mypo_parse_query_useronly' );

Hope the snippet helps. :)

Credit :
Code is taken from Allen Hollman Manage Your Post Only plugin

]]>
http://www.dynamicwp.net/articles-and-tutorials/display-posts-only-from-current-user/feed/5
How to Display Specific Category Only In Search Result http://www.dynamicwp.net/articles-and-tutorials/how-to-display-specific-category-only-in-search-result/ http://www.dynamicwp.net/articles-and-tutorials/how-to-display-specific-category-only-in-search-result/#commentsTue, 03 May 2011 15:52:01 +0000http://www.dynamicwp.net/?p=4621 Related posts:
  1. Exclude Pages or Posts of Certain Categories from WordPress Search Result
  2. How to Display Most Popular Posts from a Specific Category
  3. Best Way to Display Recent Comments with Gravatar without Plugin
]]>
While customizing a WordPress site, sometimes We also need to configure, how our WordPress site display the search result. On our previous code snippet, I have showed how to exclude specific category from search result. This tutorial will be the reserve, display the posts from specific category only in search result. Maybe this is not a good idea, because the search result will be very limited, but lets just make this as a way to know more how actually WordPress works.

How to Display Specific Category Only In Search Result

How To

Simply put the code below in the function.php of your theme.

function searchcategory($query) {
	if ($query->is_search) {
		$query->set('cat','2,5');
	}

	return $query;
}

add_filter('pre_get_posts','searchcategory');

This code will make, only post from category with ID 2 and 5 display on the search result.

Hope this tutorial help.

]]>
http://www.dynamicwp.net/articles-and-tutorials/how-to-display-specific-category-only-in-search-result/feed/0
How to Create Drop Cap to WordPress Post without Plugin http://www.dynamicwp.net/articles-and-tutorials/how-to-create-drop-cap-to-wordpress-post-without-plugin/ http://www.dynamicwp.net/articles-and-tutorials/how-to-create-drop-cap-to-wordpress-post-without-plugin/#commentsTue, 26 Apr 2011 00:36:38 +0000http://www.dynamicwp.net/?p=4557 Related posts:
  1. How to Create Fancy JQuery Tooltip for Your WordPress Post Title
  2. The Elegant Themes Drag and Drop Builder Plugin for WordPress
  3. How to Create Random Image from Post Thumbnails WordPress
]]>
A drop cap is the first letter of a paragraph that’s of a much bigger size than the rest that follow. The letter formatting is such that the letter “˜drops down’ to cover the few lines following the first one.

We can create the drop cap to by giving some styles to first letter of the post. But first we have to give a class to that first letter so we can give it the style. actually, There is a css selector for first letter. You can read a drop cap tutorial here:link. Unfortunately, the selector doesn’t work in old browser. Yes, some users are still using ie6 :)

drop cap wordpress

Here’s the script to add a class to first letter of the post. Simply put the code to your theme function.php


function post_first_letter($content = '') {
		$pattern = '/<p( .*)?( class="(.*)")??( .*)?>((|\s)*)(("|“|‘|‘|“|\')?[A-Z])/U';
		$replacement = '<p><span title="$7" class="post-first-letter">$7</span>';
		$content = preg_replace($pattern, $replacement, $content, 1 );

	return $content;
}
		
add_filter('the_content', 'post_first_letter');

Now, the first letter comes with post-first-letter class, which you can add your drop cap style.
Here’s example style that You can place in the theme style.css file

.post-first-letter {
font-size: 50px;
float: left;
margin-top: 14px; 
margin-right: 5px;
}

Credit:
The code is taken from : drop cap plugin

]]>
http://www.dynamicwp.net/articles-and-tutorials/how-to-create-drop-cap-to-wordpress-post-without-plugin/feed/10
How to Limit Character in The Post Title http://www.dynamicwp.net/articles-and-tutorials/how-to-limit-character-in-the-post-title/ http://www.dynamicwp.net/articles-and-tutorials/how-to-limit-character-in-the-post-title/#commentsWed, 20 Apr 2011 02:54:38 +0000http://www.dynamicwp.net/?p=4458 Related posts:
  1. How to Create Fancy JQuery Tooltip for Your WordPress Post Title
  2. How to Create a Stylish Post Title on your Homepage
  3. How to Restrict a Specific Word from Post Title
]]>
One of the most important elements in your blog’s web design is the post title. It reaches out and grabs people’s attention. It informs them of what the post is about, hopefully.

Sometimes, You might want to automatically limit the length of post title in the main page. This little wordpress hack will allow you to limit the displayed post title by a defined number of characters on your blogs home page.

The code snippet below should be placed somewhere within your wordpress themes functions.php. If your wordpress theme does not have a functions.php file simply create one with your favourite text editor and place it in your wordpress themes folder.

function titlelimitchar($title){
	if(strlen($title) > 55 && !(is_single()) && !(is_page())){
		$title = substr($title,0,55) . "..";
	}
	return $title;
}
add_filter( 'the_title', 'titlelimitchar' );

This code will limit post title in the homepage to 55 characters. If the title is more than 55 chars, it will be cut off and “..” will be added in the end of title.

Hope this code help :)

]]>
http://www.dynamicwp.net/articles-and-tutorials/how-to-limit-character-in-the-post-title/feed/10
How to Bold First Few Words in Excerpt http://www.dynamicwp.net/articles-and-tutorials/how-to-bold-first-few-words-in-excerpt/ http://www.dynamicwp.net/articles-and-tutorials/how-to-bold-first-few-words-in-excerpt/#commentsMon, 11 Apr 2011 01:32:08 +0000http://www.dynamicwp.net/?p=4419 Related posts:
  1. Quick Tip : Make A Post Automatic Excerpt With Image Thumbnail on WordPress 2.9+
  2. How to Hide a Part of WordPress Post or Page from Non-logged in Visitor
  3. Exclude Pages or Posts of Certain Categories from WordPress Search Result
]]>
The WordPress Excerpt is an optional summary or description of a post; in short, a post summary. It is used to truncate blog posts so that only part of the entry — the introduction or a summary of the post — is displayed, instead of the entire entry.

In my recent project, I need to bold first few words in excerpt. I’ll share the solution here.

Simply put the codes below to your theme’s function.php file


function excerpt_bold($text) {
	$text = explode(' ',get_the_excerpt());
	$text[0]='<strong>'.$text[0];
	$text[4]=$text[4].'</strong>';
	$text = implode(' ',$text);
	return $text;			
}

add_filter ('the_excerpt', 'excerpt_bold');

This code will bold first five words. You can change it to other number by replacing ’4′ in the code. But remember, the number should be number of bolded words reduced by one. If You want to bold 8 words, for example, then replace it with 7.

Hope this code snippet helps. :)

Credit :
Thanks to Alchymith and itsalltech1 at WordPress.org

]]>
http://www.dynamicwp.net/articles-and-tutorials/how-to-bold-first-few-words-in-excerpt/feed/4
How to Add “delete” and “spam” Buttons to Your Comments http://www.dynamicwp.net/articles-and-tutorials/how-to-add-del-and-spam-buttons-to-your-comments/ http://www.dynamicwp.net/articles-and-tutorials/how-to-add-del-and-spam-buttons-to-your-comments/#commentsWed, 30 Mar 2011 06:22:19 +0000http://www.dynamicwp.net/?p=4289 Related posts:
  1. Fighting Spam
  2. Best Way to Display Recent Comments with Gravatar without Plugin
  3. Quick Tip : How to Enable Threaded Comments Function in WordPress
]]>
Comment section in a site is really important. It represent interaction between you and your readers. It also keeps posts alive and is an important indicator of a popular post.

Often, We need to edit, delete or mark certain comments as spam. Yes, You can delete or mark them as spam via admin panel, but it would be really nice if We can do it from the blog. By default, WordPress shows the “Edit” link on comments (using the edit_comment_link() function) but not “Delete” or “Spam” links/buttons.

You can read our other tutorial about comment section here :

Ok, here’s the script to add those buttons.

Open your theme’s functions.php file and paste the following code :


function spam_delete_comment_link($id) {
	global $comment, $post;

	if ( $post->post_type == 'page' ) {
		if ( !current_user_can( 'edit_page', $post->ID ) )
			return;
	} else {
		if ( !current_user_can( 'edit_post', $post->ID ) )
			return;
	}

	$id = $comment->comment_ID;
    
	if ( null === $link )
		$link = __('Edit');
		

	$link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( 'Edit comment' ) . '">' . $link . '</a>';
	$link = $link . ' | <a href="'.admin_url("comment.php?action=cdc&c=$id").'">del</a> ';
	$link = $link . ' | <a href="'.admin_url("comment.php?action=cdc&dt=spam&c=$id").'">spam</a>';
	$link = $before . $link . $after;
	
	return $link;
}

add_filter('edit_comment_link', 'spam_delete_comment_link');

That’s all. Hope This snippet useful for You

credit : wprecipes and smashingmagazine

]]>
http://www.dynamicwp.net/articles-and-tutorials/how-to-add-del-and-spam-buttons-to-your-comments/feed/9