$args = array(
‘post_type’ => ‘attachment’,
‘numberposts’ => null,
‘post_status’ => null,
‘post_parent’ => $post->ID
);
$pczAttachments = get_posts($args);
if ($pczAttachments) {
foreach ($pczAttachments as $values) {
echo apply_filters(‘the_title’, $values->post_title);
the_attachment_link($values->ID, false);
}
}
Category Archives: Wordpress
Wordpress
Check if a page template is active – WordPress
Add the below given code in to your functions.php
global $wpdb;
$templateQry = “select meta_key from $wpdb->postmeta where meta_key like ‘_wp_page_template’ and meta_value like ‘Template1′”;
$result = $wpdb->query($templateQry);
if ($result) {
echo “page Template1 is active”
} else {
echo “page Template1 is not active”
}
Define a minimum word count in a post – WordPress
Add the below given code into your functions.php
function phpcodez_check_word($content){
global $post;
$num = 50; // set number of words required in a post
$content = $post->post_content;
if (str_word_count($content) < $num)
wp_die( __('The post does not have the minimum number of words') );
}
add_action('publish_post', 'phpcodez_check_word');
How to increase memory limit – WordPress
Paste the below given code in the wp-config.php
define(‘WP_MEMORY_LIMIT’, ’32M’);
How to set HTML editor as the default – WordPress
Paste the below code in the functions.php
add_filter(‘wp_default_editor’, create_function(”, ‘return “html”;’));
How to change editor font – WordPress
Paste the below given code into functions.php
add_action( ‘admin_head-post.php’, ‘phpcodez_editor_font’ );
add_action( ‘admin_head-post-new.php’, ‘phpcodez_editor_font’ );
function phpcodez_editor_font() { ?>
<style type=”text/css”>#editorcontainer #content, #wp_mce_fullscreen { font-family: “Times New Roman”, Verdana, }</style>
<?php }
How to test if an entry is custom post type – WordPress
global $wp_query;
if(“entry_value”== get_post_type($wp_query->post->ID))
echo “Its a custom post type”
Reduce spam – WordPress – .htaccess
Paste the following code in your .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post.php*
RewriteCond %{HTTP_REFERER} !.*phpcodez.* [OR] // please add your domain name
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]
</IfModule>
How to add your own meta copyright – WordPress
Paste the following code in functions.php
add_action(“wp_head”, “my_copyright_meta”);
function my_copyright_meta() {
if(is_singular()){
echo “<meta name=”copyright” content=”© phpcodez.com 2011″>”;
}
}
Increase height of the excerpt field – WordPress
Paste the following code in functions.php add_action('admin_head', 'excerpt_textarea_height'); function excerpt_textarea_height() { echo' <style type="text/css"> #excerpt{ height:500px; } </style> '; }