16
06
16

A little note to self:

StringBuilder a = new StringBuilder();

is the same as

var b = new StringBuilder();

But you can’t write

var c;
c = new StringBuilder();

In that case you must write:

StringBuilder c;
c = new StringBuilder();

Because the compilator needs to know the data type at compile time.

01
01
16

Well, the title of this article is somewhat misleading. What the code below accomplishes is to display either the_content() or the_excerpt() depending on whether you wrote an excerpt for it or not. Let’s say we have a long post, then we want to display an excerpt of that post, together with a “read more”-link. If the article is short, then we wouldn’t need to write an excerpt for it, so we would want to display the entire post.

 <?php
	if (empty($post->post_excerpt)) {
		the_content();
	}
	else {
		the_excerpt();
	}
?>        

The way this works is if you add content to the excerpt field when you write a post, then WordPress will show it, if you do not, then WordPress will show the whole post. Does that make any sense?
The code above should be applied within the loop 1, in the index.php-file.

This is more or less the way the “more” button available in WordPress works, with the difference that the excerpt lets you decide completely on what is shown on your index, whilst “more” cuts your post right after where you placed it.

The next step I am going to code is an automatic way of displaying either the_content() or the_excerpt() based on word/characters count. Stay tuned!
(more…)

01
01
16

Sometimes, we need to be able to display static HTML pages in a ASP .NET MVC project. In order to do so we have to follow a few easy steps. The order of the steps is actually irrelevant, I’ve just listed them up without any particular order.

In the RouteConfig.cs file (usually, within the App_Start folder), paste the following:

routes.MapRoute(
    name: "StaticHTMLPages",
    url: "{page}.html",
    defaults: new { controller = "Page", action = "StaticHtmlPage", page = UrlParameter.Optional }
);

Read article

20
12
15
ulven-icon-php ulven-icon-wordpress

The following code allows the use of shortcode in excerpts. This can be useful if we are using certain plugins and such where shortcode is the only way of using them. The following code lets us use shortcode in excerpts and goes in the functions.php file.

remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'custom_trim_excerpt');

function custom_trim_excerpt($text = '') {
     // ...code

Read article

20
12
15

Sometimes we need to be able to write PHP code in widgets. If that is the case, copy and paste the following code in the functions.php and voilĂ !.

add_filter('widget_text','execute_php', 100);
function execute_php($html) {
   if (strpos($html,"<"."?php")!==false) {         	
      ob_start();         	
      eval("?".">".$html);
      $html=ob_get_contents();
      ob_end_clean();
   }
   return $html;
}
20
12
15

If you want to use images instead of text links for the posts navigation, replace whatever code for previous/next post link with the following:

<?php previous_post_link('%link', '<img src="'.get_template_directory_uri().'/the-image-you-want.png/.jpg" alt="" />'); ?>
<?php next_post_link('%link', '<img src="'.get_template_directory_uri().'/the-image-you-want.png/.jpg" alt="" />') ?>

Read article