How To Show Images In WordPress Simple Fields Plugin
The following snippet will let you show images in WordPress simple fields plugin.
1 2 3 4 5 |
?php $image_id = get_post_meta(get_the_ID(), "your-id-here", true, 2); $img_src = wp_get_attachment_url($image_id, 'thumbnail'); ?> <img src="<?php echo $img_src ?>" alt="An image" /> |
How To Show Repeatable Region In WordPress Simple Fields Plugin
The following snippet will let you see repeatable region in WordPress simple fields plugin.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php $childPagesRepeatedGroup = simple_fields_get_post_group_values(get_the_id(),"Child Pages", true, 2); if ( isset($childPagesRepeatedGroup) && count($childPagesRepeatedGroup) > 0 ) { foreach ( $childPagesRepeatedGroup as $childPage ) { $imageSource = wp_get_attachment_image_src($childPage['Pic']); ?> <div class="child-links"> <img src="<?php print $imageSource[0]; ?>" width="<?php print $imageSource[1]; ?>" height="<?php print $imageSource[2]; ?>" /> <h2><?php print $childPage['Heading']; ?></h2> <p><?php print $childPage['Text']; ?></p> </div> <?php } ?> |
How To Show Specific Post And Page In WordPress
The following snippet will let you show specific post and page in WordPress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
<?php /** * put the following into functions.php **/ function new_wp_trim_excerpt($text) { $raw_excerpt = $text; if ( '' == $text ) { $text = get_the_content(''); $text = strip_shortcodes( $text ); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); $text = strip_tags($text, '<a>'); $excerpt_length = apply_filters('excerpt_length', 55); $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]'); $words = preg_split('/(<a.*?a>)|\n|\r|\t|\s/', $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE ); if ( count($words) > $excerpt_length ) { array_pop($words); $text = implode(' ', $words); $text = $text . $excerpt_more; } else { $text = implode(' ', $words); } } return apply_filters('new_wp_trim_excerpt', $text, $raw_excerpt); } remove_filter('get_the_excerpt', 'wp_trim_excerpt'); add_filter('get_the_excerpt', 'new_wp_trim_excerpt'); function my_excerpt($excerpt = '', $excerpt_length = 50, $readmore = "Read more»", $tags = '<a>', $permalink = null) { global $post; $excerpt = strip_tags($excerpt, $tags); $excerpt = strip_shortcodes($excerpt); $string_check = explode(' ', $excerpt); if ($permalink === null) { $permalink = get_permalink(); } if (count($string_check, COUNT_RECURSIVE) > $excerpt_length) { $new_excerpt_words = explode(' ', $excerpt, $excerpt_length+1); array_pop($new_excerpt_words); $excerpt_text = implode(' ', $new_excerpt_words); $temp_content = strip_tags($excerpt_text, $tags); $short_content = preg_replace('|\[(.+?)\](.+?\[/\\1\])?|s','',$temp_content); $short_content .= '... <a href="' . $permalink . '">' . $readmore . '</a>'; return $short_content; } else { return $excerpt . ' <a href="' . $permalink . '">' . $readmore . '</a>'; } } ?> <?php /** * put the following in your template and change the post id **/ ?> <?php $my_post_id = 495; /* change this to match the post you are trying to retreive */ ?> <?php $my_post = get_post($my_post_id); ?> <h2><?php echo $my_post->post_title; ?></h2> <?php $my_content = str_replace(']]>', ']]>', apply_filters('the_content', $my_post->post_content)); ?> <!-- this will output the content in excerpt format. change the '80' to whatever length you want. --> <p><?php echo my_excerpt($my_content, 80, 'Read more»', '<a>', get_permalink($my_post_id) ); ?></p> <!-- this will output all of the content from that post/page --> <?php echo $my_content; ?> |
How To Solve Multiple Loops Problem In WordPress
The following snippet will let you solve multiple loops problem in WordPress.
1 |
<?php wp_reset_query(); ?> |
How To Speed Up Your WordPress
The following snippet will let you speed up your WordPress by placing the following in the .htaccess file, replacing the standard WordPress .htaccess code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# BEGIN WordPress RewriteEngine on # # Unless you have set a different RewriteBase preceding this # point, you may delete or comment-out the following # RewriteBase directive: RewriteBase / # # if this request is for "/" or has already been rewritten to WP RewriteCond $1 ^(index\.php)?$ [OR] # or if request is for image, css, or js file RewriteCond $1 \.(gif|jpg|css|js|ico)$ [NC,OR] # or if URL resolves to existing file RewriteCond %{REQUEST_FILENAME} -f [OR] # or if URL resolves to existing directory RewriteCond %{REQUEST_FILENAME} -d # then skip the rewrite to WP RewriteRule ^(.*)$ - [S=1] # else rewrite the request to WP RewriteRule . /index.php [L] # # END wordpress |
Snippet Source/Credit: Canonicalseo.com