add css and javascript file to admin in wordpress theme

WordPress Tutorial, add css and javascript file to admin in wordpress theme. Many developers want to add the javascript and css files into wordpress themes.

add css and javascript file to admin in wordpress theme

You just need to add following code into functions.php file.

// Register your javascript for properties
function admin_your_javascript(){
    global $post;
    if($post->post_type == 'post-type' && is_admin()) {
        wp_enqueue_script('YOUR-JS', WP_CONTENT_URL . '/themes/YOUR-THEME/js/YOUR-JS.js');

    }
}
add_action('admin_print_scripts', 'admin_your_javascript');

// Register your styles for properties
function admin_your_styles(){
    global $post;
    if($post->post_type == 'post-type' && is_admin()) {
        wp_enqueue_style('YOUR-CSS', WP_CONTENT_URL . '/themes/YOUR-THEME/css/YOUR-CSS.css');
    }
}
add_action('admin_print_styles', 'admin_your_styles');

You just need to replace Your theme name and javascript and css file name.

add css and javascript file to admin in wordpress theme
add css and javascript file to admin in wordpress theme

Show comments from custom post type in wordpress

WordPress tutorial, Show comments from custom post type in wordpress. we shows comments in sidebar. But what to do for show comments for custom post type.

Show comments from custom post type in wordpress

It’s not well documented, but according to the codex, you can pass a ‘post_type’ variable in the get_comments function.

<?php
 $comments = get_comments('number=10&status=approve&post_type=YOUR_POST_TYPE');
foreach($comments as $comment) :

// comment loop code will go here

endforeach;
?>

Note: This code only useful after wordpress 3.1 version.

Show comments from custom post type in wordpress
Show comments from custom post type in wordpress

Change image name to wordpress post slug during upload

WordPress tutorial, Change image name to wordpress post slug during upload. If you want to rename files during upload and set their names to the post slug.

If you want to rename files during upload and set their names to the post slug the files are being attached to, plus some random characters (a simple incremental counter will be just fine) to make the filenames different.

Change image name to wordpress post slug during upload

Change image name to wordpress post slug during upload
Change image name to wordpress post slug during upload

In other words, if you are uploading/attaching images to the post whose page slug is “test-page-slug”, i’d like for the images to be renamed on the fly to test-page-slug-[C].[original_extension] — test-page-slug-1.jpg, test-page-slug-2.jpg etc (no matter what the original filenames were).

This is very easy. You just need to use following hook in functions.php file.

function wp_modify_uploaded_file_names($image_name) {

    // Get the parent post ID, if there is one
    if( isset($_GET['post_id']) ) {
        $post_id = $_GET['post_id'];
    } elseif( isset($_POST['post_id']) ) {
        $post_id = $_POST['post_id'];
    }

    // Only do this if we got the post ID--otherwise they're probably in
    //  the media section rather than uploading an image from a post.
    if(is_numeric($post_id)) {

        // Get the post slug
        $post_obj = get_post($post_id);
        $post_slug = $post_obj->post_name;

        // If we found a slug
        if($post_slug) {

            $random_number = rand(10000,99999);
            $image_name['name'] = $post_slug . '-' . $random_number . '.jpg';

        }

    }

    return $image_name;

}
add_filter('wp_handle_upload_prefilter', 'wp_modify_uploaded_file_names', 1, 1);

This is very easy.
if you have pretty permalinks enabled, so I’ve added a check to make sure there is a slug before renaming the file. You’ll also want to consider checking the file type, which I haven’t done here–I’ve just assumed it’s a jpg.

Solved: qTranslate slug with Widget not working with pages

We just saw the issue with qtranslate slug with widget is not working for 0.5 version. URL is showing but URL is not opening and 404 page is opening. we solved  the of qTranslate slug with Widget not working with pages.

Solved issue qTranslate slug with Widget not working with pages

The problem was exactly at the function qTranslateSlug_filter_request inside de file qtranslate-slug-with-widget.php, which is the only one of the plugin, so it’s easy to find.
We must take a look at this part of the code:

if (isset($q['name'])) {
    $type = QTS_POST;
    $slug = $q['name'];
    $param = 'p';
    $get_link = 'get_permalink';
    unset($new_q['name']);
} else if (isset($q['pagename'])) {
    //$type = QTS_PAGE;
    //$slug = $q['pagename'];
    //$param = 'page_id';
    $id = qTranslateSlug_get_page_by_path($q['pagename'], $lang);
    if ($id) {
        unset($new_q['pagename']);
        $q = $new_q;
        $q['page_id'] = $id;
        $get_link = 'get_page_link';
    }
} else if (isset($q['category_name'])) {
    $type = QTS_CAT;
    $slug = $q['category_name'];
    $param = 'cat';
    $get_link = 'get_category_link';
    unset($new_q['category_name']);
} else if (isset($q['tag'])) {
    $type = QTS_TAG;
    $slug = $q['tag'];
    $param = 'tag_id';
    $get_link = 'get_tag_link';
    unset($new_q['tag']);
}

That we hace to replace with the following:

if (isset($q['name'])) {
        $id = qTranslateSlug_get_page_by_path($q['name'], $lang);
        if ($id) {
            unset($new_q['name']);
            $q = $new_q;
            $q['page_id'] = $id;
            $get_link = 'get_page_link';
        } else {
            $type = QTS_POST;
            $slug = $q['name'];
            $param = 'p';
            $get_link = 'get_permalink';
            unset($new_q['name']);
        }
    } else if (isset($q['pagename'])) {
        $id = qTranslateSlug_get_page_by_path($q['pagename'], $lang);
        if ($id) {
            unset($new_q['pagename']);
            $q = $new_q;
            $q['page_id'] = $id;
            $get_link = 'get_page_link';
        }
    } else if (isset($q['category_name'])) {
        $type = QTS_CAT;
        $slug = $q['category_name'];
        $param = 'cat';
        $get_link = 'get_category_link';
        unset($new_q['category_name']);
    } else if (isset($q['tag'])) {
        $type = QTS_TAG;
        $slug = $q['tag'];
        $param = 'tag_id';
        $get_link = 'get_tag_link';
        unset($new_q['tag']);
    } else {
        $path = trim(preg_replace('/\?(.*)/', '', $_SERVER['REQUEST_URI']), '/');
        $id = qTranslateSlug_get_page_by_path($path, $lang);
        if ($id) {
            if (isset ($q['attachment'])) {
                unset($q['attachment']);
                unset($new_q['attachment']);
            }
            $q = $new_q;
            $q['page_id'] = $id;
            $get_link = 'get_page_link';
        }
    }
Solved: qTranslate slug with Widget not working with pages
Solved: qTranslate slug with Widget not working with pages

With the last wordpress versions, mine is 3.3.1, has changed the way of passing the query to the request filter, changing the array slug position from ‘pagename’ to ‘name’, then the plugin didn’t have a way to find any page, since it expected to find in the array the position ‘pagename’, nonexistent for the current case.
Ref is taken from – http://en.codatavern.com/qtranslate-slug-with-widget-wordpress-plugin-fix/

what’s new in wordpress 3

WordPress news, what’s new in wordpress 3. wordpress 3.3 is released on 12th Dec 2011. This is next biggest release of 2011. We given full release notes.

what is new in wordpress 3.3

what is new in wordpress 3.3
what is new in wordpress 3.3

Highlights

  • Easier Uploading
    • File Type Detection – A single upload button
    • Drag-and-Drop Media Uploader
  • Dashboard Design
    • New Toolbar in the dashboard, combining the Admin Bar and admin header
    • Responsive design for some screens, including iPad/tablet support
    • Flyout menus, providing single-click access to any screen
  • New User Experience
    • New feature pointers, helping users navigate new features
    • Post-update About screen
    • Dashboard welcome area for new installs
  • Content Tools
    • Better co-editing that releases post locks immediately
    • Don’t lose widgets when switching themes
    • Tumblr Importer
  • Under the Hood improvements
    • Use the postname permalink structure without a performance penalty
    • Improved Editor API
    • is_main_query() function and WP_Query method
    • Remove a number of funky characters from post slugs
    • jQuery 1.7.1 and jQuery UI 1.8.16
    • A new Screen API for adding help documentation and adapting to screen contexts
    • Improved metadata API
  • Performance improvements and hundreds of bug fixes

User Features

General

  • Admin doctype changed to HTML5 (#18202)
  • Show Toolbar in backend by default (#17899)
  • Drag and drop multi-file uploading (except older IE)
  • Fix Press This editors
  • Switch admin menus to flyouts from dropdowns
  • WebMatrix support
  • Improve cron locking; avoid multiple cron processes looping over the same events
  • Add pointers feature, and pointer to admin bar
  • Introduce help tabs and WP_Screen
  • Style tweaks to the update nag

Dashboard

  • Ensure text in the dashboard recent comments widget wraps up properly

Posts

  • When inserting a Gallery to be ordered by Date/Time use the post_date field for ordering rather than ID
  • Rename ‘Post Tags’ to ‘Tags’
  • Make DFW (Distraction-Free Writing) content width match exactly the reported width from the theme
  • Improve the image drag-resize detection in the visual editor (supported in FF and IE only), remove the size-* class if the image is soft-resized
  • Add TinyMCE command to handle opening of the upload/insert popup, fix the shortcut “Alt+Shift+M”, fix the “image” button in DFW
  • Allow Apostrophes in Post Passwords
  • Add post formats to quick edit and bulk edit
  • Hide post title field in DFW if title is not supported by the current post type or missing
  • Clean up remnants from having negative Post_ID

Media

  • Merge media buttons into one
  • Add the styling for “drop area” to Media->Add New
  • Add support for rar and 7z file uploading

Links

Comments

  • Use WP_Editor when editing or replying to comments
  • Use ‘View Post’ instead of ‘#’ for view post links in comment rows

Appearance

  • Use the Settings fields/sections API in Twenty Eleven
  • Load all Parent theme stylesheets before Child theme stylesheets in the TinyMCE Editor
  • Clean up Plugin/Theme uploads after successfully installing them
  • Improved Theme upload and validation
  • Avoid losing widgets when switching themes
  • Make Distraction Free Writing content width match exactly the reported width from the theme
  • Allow current_theme_supports() to be used to check for specific post formats
  • Improved Menus
  • Contextual help for Twenty Eleven theme options page

Plugins

  • Improved Plugin upload and validation
  • Stop remembering the last viewed plugins screen; always show all plugins when returning to plugins.php

Tools

  • Add the Tumblr importer to the Importers List
  • Add wxr_export_skip_postmeta filter for skipping postmeta in exports

Users

  • Removed user option to disable Toolbar (admin-bar in 3.2) in the Dashboard

Settings

  • Add postname to Settings > Permalinks and remove the help text talking about permalink performance; make the slugs (and /archives/ rewrite base) translatable
  • Clarify Settings > Privacy
  • Use title case in Settings > General
  • Disallow indexing wp-admin and wp-includes in robots.txt

Install Process

Multisite

  • Allow creating sites with IDN domains
  • Move network/settings.php POST handling out of network/edit.php
  • Dissolve wp-admin/network/edit.php
  • Add ‘Network Enable’ link after installing a theme in the network admin
  • Use update_blog_details() in wpmu_update_blogs_date()
  • Change Network Settings to just Settings
  • Implement bulk update for network/themes.php
  • Fix inviting existing users to a site with email confirmation
  • Check for plugin/theme updates every hour when hitting update-core.php, not just themes.php/plugins.php

Development, Themes, Plugins

  • Abstract word-trimming from wp_trim_excerpt() into wp_trim_words()
  • Add wp_unique_post_slug filter
  • Add _doing_it_wrong() when a plugin or theme accesses $wp_scripts or $wp_styles too early (also fixes localization)
  • Add a filter to is_multi_author()
  • Add a general filter to wp_unique_post_slug to allow for full customisation of the uniqueness functionality
  • Add filter for the args into wp_dropdown_pages() in the page attributes box; give the list_pages filter the context of the post object
  • Add filter so the users can select custom image sizes added by themes and plugin
  • Add filters for install/upgrade queries, so that unit tests installer can force creating InnoDB tables, so that we can use transactions to revert the database to its initial state after each test
  • Add inflation support for java.util.zip.Deflater in WP_Http_Encoding::compatible_gzinflate()
  • Add magic get/set/isset methods to WP_User to avoid data duplication; standardize on WP_User::ID
  • Add pre_ent2ncr filter
  • add_site_option should not update existing options, should return a boolean and should only run actions on success
  • Allow get_blog_option(null,…) to hit the cache for the current blog; new return values for add_blog_option, update_blog_option, delete_blog_option; don’t set the cache in those functions if add/update/delete_option failed
  • Allow ‘id’ to work in get_bookmarks(); add link_notes even though such sorting is a bad idea
  • Allow sorting by id in get_bookmarks()
  • Allow the text parameter in wp_trim_excerpt() to be omitted altogether, instead of requiring a blank string
  • Automatically set ‘compare’ => ‘IN’ in WP_Meta_Query::get_sql() when the meta value is an array
  • Change month dropdown display in date pickers to include month number
  • Completely remove wp_add_script_data()
  • Consolidate update count code into wp_get_update_data()
  • Count only published posts when updating term counts; fire term count updates on transition_post_status
  • Deprecate add_contextual_help() for get_current_screen()->add_help_tab()
  • Deprecate favorite_actions(), add_contextual_help(), add_screen_option(), move meta_box_prefs() and get_screen_icon() in WP_Screen
  • Deprecate get_userdatabylogin() and get_user_by_email()
  • Deprecate media_upload_(image|audio|video|file)(), type_url_form_(image|audio|video|file)(); these now wrap wp_media_upload_handler() and wp_media_insert_url_form()
  • Deprecate RSS 0.92 feed and 301 it to the default feed
  • Deprecate screen_options(), screen_layout(), screen_meta()
  • Deprecate wpmu_admin_redirect_add_updated_param() and wpmu_admin_do_redirect()
  • Eliminate verbose rewrite rules for ambiguous rewrite structures, resulting in massive performance gains
  • Fix back compat issues with delete_postmeta and deleted_postmeta actions as these should be passed the meta ID
  • Fix QTags.closeAllTags(), replace ‘tb’ with ‘ed’ in quicktags,js to make it clear it is the editor instance not the toolbar, small comments quick edit fixes
  • Fix typos in documentation
  • Fix wp_update_user() so it doesn’t stomp meta fields
  • Force display_errors to off when WP_DEBUG_DISPLAY == false; technically a backwards incompatible change so if you want the passthrough to php.ini (which false used to provide) then use WP_DEBUG_DISPLAY === null
  • Harden up is_user_logged_in() against empty $current_user instances to prevent PHP Notices on XML-RPC requests
  • Have dbDelta() loop through tables it knows about, rather than loop through a potentially expensive and definitely unnecessary SHOW TABLES
  • Improve _wp_menu_output()
  • Improve the parsing of email addresses in wp_mail to re-support RFC2822 nameless “<address@…>” style
  • Instantiate some MS variables as objects before using them
  • Introduce ->mysql to allow drop-ins to declare themselves as MySQL and therefore allow minimum version checks to still apply
  • Introduce is_main_query() that compares the query object against $wp_the_query
  • Introduce metadata_exists(), WP_User::get_data_by(), WP_User::get(), WP_User::has_prop(). Don’t fill user objects with meta
  • Introduce new hooks, registered_post_type for register_post_type, and registered_taxonomy for register_taxonomy
  • Introduce register_meta(), get_metadata_by_mid(), and *_post_meta capabilities
  • Introduce wp_allowed_protocols() for use in wp_kses() and esc_url()
  • Introduce wp_cache_incr() and wp_cache_decr()
  • Introduce WP_Dependencies::get_data() method, change scripts and styles priority to follow the “natural” order in HTML, i.e. the last one wins
  • Introduce wp_get_db_schema() for retrieving various flavors of db schema; eliminates need to use global; allows multiple calls to wpmu_create_blog()
  • Introduce wp_no_robots() and call it for pages that should never be indexed, regardless of blog privacy settings
  • Introduce wp_suspend_cache_addition() to allow reduced memory usage when cache additions aren’t useful
  • Make check_theme_switched() run an action so plugins and themes authors can avoid losing widgets when switching themes
  • Optimise get_term to not query for term_id = 0 and improve the prepared query to use %d for the term_id
  • Optimize parse_request for the home page
  • Performance improvement for wp_list_pluck()
  • Properly handle display of Order, Template, and Parent page attributes in Quick/Bulk Edit
  • Properly handle nested arrays in wp_list_filter()
  • Recognize urls that start with a question mark as relative urls that do not require a scheme to be prepended
  • Refactor Quicktags
  • Remove return by ref from get_role()
  • Remove support for <link rel=start>, end, up, and index. These rel=”” values have been dropped by the HTML Working Group
  • Remove the old root feed files, but don’t add these files to old_files to leave them on existing installs
  • Require show_ui rather than public for a taxonomy’s parent post type
  • Rework get_hidden_meta_boxes() to leverage a full WP_Screen object; prevents custom post types from having their explicitly supported meta boxes being hidden by default
  • Set up the post global variable in the comment feed loops so that any calls to post related template tags work correctly
  • Store screen help and options as static data against WP_Screen; individual screen objects no longer hold data it can’t re-generate on construction or otherwise fetch; convert_to_screen() now returns a WP_Screen object; various globals are gone; introduces WP_Screen::get_option(); allows for a formal factory to be introduced later
  • Support an array or comma-seperated list of excluded category IDs in get_adjacent_post()
  • Support for using wp_enqueue_script() and wp_enqueue_style() in the HTML body; all scripts and styles are added in the footer
  • Sync pomo library with the current GlotPress version
  • Turn delete_meta() , get_post_meta_by_id(), update_meta(), delete_post_meta_by_key() into wrappers around theMetadata API; add back compat *_postmeta actions to Metadata API
  • Turn is_blog_user() into a convenience wrapper around get_blogs_of_user(); fixes is_blog_user() for blog prefixes that do not contain a blog ID
  • Update blog last_updated time only on publish_post; both private_to_published and publish_phone are overly broad and otherwise redundant
  • Update jQuery to 1.7.1
  • Update jQuery UI to 1.8.16
  • Update Plupload to 1.5.1.1
  • Update quicktags.js (HTML editor)
  • Update TinyMCE to 3.4.5
  • Use add_option() method, introduce add_option_context() method for adding specific text above the screen options
  • Use get_template_directory() instead of TEMPLATEPATH in Twentys Ten and Eleven
  • Use json_encode() for adding script data (formerly l10n); add the same functionality to WP_Styles for adding inline css after a stylesheet has been outputted
  • Use wp_print_scripts() in install.php
  • Various PHPdoc updates including: for all_items, menu_name, WP_List_Table::views(), cache.php, get_option(), wpdb::prepare(), get_template_part(), esc_url(), get_meta_sql(), WP_Screen, WP_Http_Encoding::compatible_gzinflate(), zeroise(), wp_add_script_before(), wp_editor()
  • WP_Filesystem_*::mkdir() untrailingslash path consistently, don’t waste time attempting to create an “empty” path

how to integrate wordpress into php website

WordPress is very easy to work on. PHP tutorial, how to integrate wordpress into php website. you can very easily integrate the wordpress with php or html site. Here we given code for same.

There may be only a few features of WordPress you want to use when integrating it with your site, or you may want your entire site run with WordPress. This tutorial will guide you through making your WordPress site look like your current design.

how to integrate wordpress into php website

How to start?
First you need to disable the wordpress theme. using following code.

open your header.php file from your wordpress theme and put following code in that file.

<?php
/* Short and sweet */
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
?>

Create any php file and put following code in that file.

<?php
require('/the/path/to/your/wp-blog-header.php');
?>

In the event you want to show ten posts sorted alphabetically in ascending order on your web page, you could do the following to grab the posted date, title and excerpt:

<?php
require('/the/path/to/your/wp-blog-header.php');
?>

<?php
$posts = get_posts('numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) : start_wp(); ?>
<?php the_date(); echo "<br />"; ?>
<?php the_title(); ?>
<?php the_excerpt(); ?>
<?php
endforeach;
?>
how to integrate wordpress into php website
how to integrate wordpress into php website

For more information you can write to me.

In wordpress add tags and categories to custom post type

Many times we use the custom post type in wordpress. Wordpres tutorial, In wordpress add tags and categories to custom post type.  Some times we need to category and tags for custom post type which associated.

In wordpress add tags and categories to custom post type

you can use the following code in functions.php file.

// === CUSTOM POST TYPES === //
function create_my_post_types() {
	register_post_type( 'Services',
		array(
			'labels' => array(
				'name' => __( 'Services' ),
				'singular_name' => __( 'Services' ),
				'add_new_item' => 'Add New Services',
				'edit_item' => 'Edit Services',
				'new_item' => 'New Services',
				'search_items' => 'Search Services',
				'not_found' => 'No Services found',
				'not_found_in_trash' => 'No Services found in trash',
			),
			'_builtin' => false,
			'public' => true,
			'hierarchical' => false,
			'taxonomies' => array( 'website_type', 'service'),
			'supports' => array(
				'title',
				'editor',
				'excerpt',
                                'thumbnail'
			),
			'rewrite' => array( 'slug' => 'services', 'with_front' => false ),

		)
	);
}
add_action( 'init', 'create_my_post_types' );

// === CUSTOM TAXONOMIES === //
function my_custom_taxonomies() {
	register_taxonomy(
		'website_type',		// internal name = machine-readable taxonomy name
		'Services',		// object type = post, page, link, or custom post-type
		array(
			'hierarchical' => true,
			'label' => 'Website Types',	// the human-readable taxonomy name
			'query_var' => true,	// enable taxonomy-specific querying
			'rewrite' => array( 'slug' => 'website_type' ),	// pretty permalinks for your taxonomy?
		)
	);
	register_taxonomy(
		'service',
		'post',
		array(
			'hierarchical' => false,
			'label' => 'Service',
			'query_var' => true,
			'rewrite' => array( 'slug' => 'service' ),
		)
	);

}
add_action('init', 'my_custom_taxonomies', 0);

Please consult with your developer.

In wordpress add tags and categories to custom post type
In wordpress add tags and categories to custom post type

 

……………………..

Solved allowed memory size of 33554432 bytes exhausted wordpress

We solved Allowed memory size of 33554432 bytes exhausted which for wordpress. Given solution for allowed memory. Change given for wordpress/wp-config.php file.

Solved Allowed memory size of 33554432 bytes exhausted

We got always following ERROR PHP Fatal error:

Allowed memory size of 33554432 bytes exhausted (tried to allocate 10485761 bytes)

This issue with old and new wordpress versions both. First you need to increase memory limit for your php package. Use following method for increase the memory for php.

Open php configuration file


# vim /etc/php.ini

Change following sections:

max_execution_time = 300 ; Maximum execution time of each script, in seconds
max_input_time = 300 ; Maximum amount of time each script may spend parsing request data
memory_limit = 128M ; Maximum amount of memory a script may consume (16MB)

After this dont forget to restart apache server.

I know on 2.5.1 i needed to increase the memdory, but i don’t know how in 2.6. in the wp-config.php there no define to increase memory. If you are using old wordpress version less than wordpress 2.6 version or you are using the wordpress MU then use following code. open your wp-settings.php file from root folder and change following line

if ( !defined('WP_MEMORY_LIMIT') )
        define('WP_MEMORY_LIMIT', '32M');
to
if ( !defined('WP_MEMORY_LIMIT') )
        define('WP_MEMORY_LIMIT', '128M');

If you are using the newer wordpress version greater than 2.7 then use following method. Following URL is also helpful http://codex.wordpress.org/Editing_wp-config.php

#Increasing_memory_allocated_to_PHP Edit wp-config.php and enter the following line


define('WP_MEMORY_LIMIT', '64M');

If you are using the shared hosting then use following method.

  •  Create a file called php.ini in the root of your site (if you are using a hosted addon domain, this must be in the subdirectory of that site)
  • In php.ini, enter a line that says memory_limit = 64MB 3. In your site’s .htaccess (being a WordPress blog, I’m assuming there is one), enter the following line SetEnv PHPRC // (keep the slashes)
  • Edit wp-config.php and enter the following line

define('WP_MEMORY_LIMIT', '64M');

  • Upload the new files to the server Oh, and don’t tell your hosting provider you’ve done this… This will solve your issue.
Solved Allowed memory size of 33554432 bytes exhausted
Solved Allowed memory size of 33554432 bytes exhausted

solved wordpress custom post type pagination not working

From wordpress 3.0 version, wordpress started the custom post type functionality. There are API provided by wordpress for adding the pagination for custom post type. Some WP developers asked me about pagination of custom post type. That is very easy to add the pagination. Here in this article I given the code snippet for showing the pagination in custom post type.

solved wordpress custom post type pagination not working

For showing the custom post type we always use the query_post method.

Just use the following code in your template or theme file.

<?php get_header(); ?>

            <?php  query_posts( 'post_type=custom-post-type&paged='.$paged );
                                    if (have_posts()) : while (have_posts()) : the_post(); ?>

//loop here

              			<?php endwhile; ?>
				  <div id="nav-below" class="navigation">
					<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyten' ) ); ?></div>
					<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
				  </div><!-- #nav-below -->
				  <?php endif; wp_reset_query(); ?>

<?php get_footer(); ?>
solved wordpress custom post type pagination not working
solved wordpress custom post type pagination not working

Have fun!

How to remove first image from wordpress post with caption

I struggled lot for this issue. Some times I only removed the first image. some times I removed first caption. Using following code you can easily remove the post first image and caption.

How to remove first image from wordpress post with caption if caption is present

I used the following code for first image removing.

/*
 * Removing the first image from post
 */
function remove_first_image ($content) {
 if (!is_page() && !is_feed() && !is_feed() && !is_home()) {
    if (preg_match("/<img[^>]+\>/i",$content)) {
		 $content = preg_replace("/<img[^>]+\>/i", "", $content, 1);
 	}
	return $content;
   }
}

But I faced the some issues with that code. When first image has caption then only image get removed and caption will remain there.

After that I used the following code for caption remove.

/*
 * Removing the first caption from post with image
 */
function remove_first_image_caption ($content) {
 if (!is_page() && !is_feed() && !is_feed() && !is_home()) {
 $content = preg_replace("(\)", "", $content, 1);
 } return $content;
}
add_filter('the_content', 'remove_first_image_caption');

But if first image has no caption and second image image has caption then both the images will be get removed from post.

After some struggle I written following code. Following is the solution:

Final Code.

/*
 * Removing the first image from post
 * functionality added to delete caption is present to first image.
 */
function remove_first_image ($content) {
 if (!is_page() && !is_feed() && !is_feed() && !is_home()) {
    if (preg_match("/<img[^>]+\>/i",$content)) {
    //find first image URL
     $first_img = '';
     $output = preg_match_all('/< *img[^>]*src *= *["\']?([^"\']*)/', $content, $matches);
     $first_img = $matches[1][0];

    //find first image caption inner text
     $output = preg_match_all("/caption=['"](.*)/", $content, $matches);

     //find first image present in first caption text or not
        $pos = strpos($matches[0][0], $first_img);

    // if image URL found in caption array then delete the caption and image
        if ($pos !== false) {
           $content = preg_replace("(\)", "", $content, 1);
        } else {
           $content = preg_replace("/<img[^>]+\>/i", "", $content, 1);
        }
    }

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

solved: pagination for Custom post type not working

Some people asked me about pagination of custom post type. That is very easy.

For showing the custom post type we always use the query_post method.

Just use the following code in your template or theme file.

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php get_header(); ?>

            <!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php  query_posts( 'post_type=custom-post-type&paged='.$paged );
                                    if (have_posts()) : while (have_posts()) : the_post(); ?>

loop here

              			<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php endwhile; ?>
				  <div id="nav-below" class="navigation"></pre>
<div class="nav-previous"><!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyten' ) ); ?></div>
<pre></pre>
<div class="nav-next"><!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyten' ) ); ?></div>
<pre>
				  </div><!-- #nav-below -->
				  <!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php endif; wp_reset_query(); ?>

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php get_footer(); ?>
remove first image from wordpress post with caption
remove first image from wordpress post with caption
How to remove first image from wordpress post with caption if caption is present