Passing a hardcoded page/post ID into `get_post`

For starters let’s dive into what is 5 really. It is the post’s ID. But what is ID in turn? It is value in the MySQL table row which identifies the specific post record. Issues with using IDs So first there are some conceptual problems with it. It’s not content. It’s not something user creates, … Read more

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.

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