Displaying content of single post

Create a file named single.php. This will automatically get all you single posts. For more information about WordPress’ template hierarchy, read the Codex Inside single.php, run the default loop and get header.php, sidebar.php and footer.php <?php get_header(); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php the_title(); ?> <?php the_content(); ?> <?php echo … Read more

How can you change the ‘Insert into Post’ title in the media button?

add_filter(“attribute_escape”, “myfunction”, 10, 2); function myfunction($safe_text, $text) { return str_replace(“Insert into Post”, “Use this image”, $text); } Place in your theme functions file of in a plugin file. The first usable filter that this button hits is on the function esc_attr(). So what that code will do is find any instance of Insert into Post … Read more

Execute function when post is published

The correct action is ‘draft_to_publish’. To be sure you used the correct status try to get a list of all registered post statuses (including custom statuses) with: <pre><?php print ‘- ‘ . implode( “\n- “, array_keys( get_post_stati() ) );?></pre> On a vanilla installation you should get: publish future draft pending private trash auto-draft inherit Note … Read more

How to get the number of posts in a selected category?

If you are on a category archive you don’t need to query all the posts of the category like Christopher Ross suggested and you can’t use get_the_category() like Max Yudin suggested unless you are already in the loop. What you can do is simply get the current category object using get_queried_object() which will hold the … Read more

how to get a different html for odd/even posts?

You don’t need a new variable for counting posts, WordPress has one already in $wp_query->current_post. <?php while (have_posts()): the_post() ?> <?php if ($wp_query->current_post % 2 == 0): ?> even <?php else: ?> odd <?php endif ?> <?php endwhile ?> If you use a custom WP_Query instance as iEmanuele suggested then it will be $query->current_post instead.

WP_Query offset argument does not work

The offset index for WP_Query generally works with pagination. When you set pagination to a -1 the function assumes you’re getting all posts and there will be no pagination or offset. So to counteract this you would set the posts_per_page to a high number like 999. Reading the Function Reference on WP_Query the pagination section … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)