Tag Info

Hot answers tagged

7

Yes, as you - so far - have no publish date. You could use $post->post_modified, which will always be the date of the latest modification to the post data. Debug: Try hooking into the filter and dump both vars: function date_dump_callback( $date, $d ) { echo '<pre>'; print_r( $date ); print_r( $d ); echo '</pre>'; return $date; ...


6

First you need to get all the assigned tag id:s by calling wp_get_post_tags because the include parameter in wp_tag_cloud only works with tags id, Not page id. So when you have all the id:s put them in the include parameter within the wp_tag_cloud like this: <?php // Get the assigned tag_id $tag_ids = wp_get_post_tags( $post->ID, array( ...


6

My answer adds a class to the <body> element via the body_class filter. This is probably the easiest way to apply extra formatting to any element on the page. The added classes are wpse14430_products, wpse14430_services or wpse14430_contact (based on the slugs of the top pages in your example). Using wp_nav_menu() If you use wp_nav_menu() to display ...


6

There's a good chance your HTML is not included in the loop. Make sure your code looks like this: if(have_posts()): while(have_posts()): the_post(); ?> <div class="publication-info"> <?php printf("<h2>%s</h2>", get_the_title() ); ?> <div class="publication-meta publication-credit"><?php ...


4

Try this code. $author = get_user_by( 'slug', get_query_var( 'author_name' ) ); echo $author->ID;


4

$wp_query->get_queried_object() is a very versatile function. It will return the current category, tag, custom taxonomy term, author, page or post, depending on the page/archive you are viewing. Especially handy if you want to simplify your archive headings.


4

Damn, so I did find the answer I was looking for: $thisCat = get_category(get_query_var('cat'),false); Never mind :-)


4

To get the category object use get_category (codex). It's easy if you know the name, slug or ID, but if you don't you could use is_category to check on which category you are and pass the ID to get_category.


4

The Codex page for is_single should be updated, what you're seeing is correct behavior. According to the main Conditional Tags Codex page: is_single() When any single Post (or attachment, or custom Post Type) page is being displayed. (False for Pages) You can exclude attachments by also checking ! is_attachment(). Also, you may want to move that ...


3

I'm not sure why it is modifying the data like that when displaying, but you can use $post->post_date_gmt This will return the scheduled post date the same as it is in the DB except it's in GMT time format, so you might need to convert the time to your local time zone first (this blog post may help). Otherwise, you should be able to use it as is if ...


3

When your going through your loop add this: global $post; $post = get_post( $ID, OBJECT ); setup_postdata( $post ); //Do something wp_reset_postdata();


3

Since editor displays projected permalink for slug editor, it must have some way to figure it out. From looking at source that is handled by get_sample_permalink_html() and get_sample_permalink(). Since we only need link without form cruft, we can rework it into something like: function get_draft_permalink( $post_id ) { require_once ABSPATH . ...


3

Check for global variable $wp_customize: if ( empty ( $GLOBALS['wp_customize'] ) ) { // show something } Update: in WordPress 4.0, you can use is_customize_preview().


3

I would recommend you use home_url() to get the URL to the front page of the currently viewed site. If you want to get the main site URL (the network home), use network_home_url().


3

I came to a solution for this by reviewing the Wordpress Codex. The trick is to turn off the automatic echo of wp_list_categories, and then use str_replace(). My example follows: <?php $variable = wp_list_categories('child_of=270&style=none&echo=0'); ?> <?php $variable = str_replace('<br />', '', $variable); ?> <?php echo ...


3

$posts = get_posts(array('name' => 'your-posts-name', 'post_type' => 'faq')); foreach ($posts as $post) { $title = get_the_title($post->ID); $permalink = get_permalink($post->ID); break; //use this to limit to a single result }


3

wp_list_categories() is a simple function that returns (or echos, depending on parameter) a list of links to category archives. It needs not to be reset. When you create a new instance of the WP_Query class you need to reset postdata, because Template Tags otherwise use that query and not the main query. You've said: I'm using two of these queries ...


2

This is a little "hacky", but when you call get_permalink and you need the permalink from a draft, provide a clone of your post object with the details filled in: global $post; if (in_array($post->post_status, array('draft', 'pending', 'auto-draft'))) { $my_post = clone $post; $my_post->post_status = 'published'; $my_post->post_name = ...


2

I just finished posting this My Options Panel a couple of hours a ago which will answers you question.


2

Even if your image doesn't cover the typical full-width area you're used to seeing in twentyten and twentyeleven, add_custom_image_header is the appropriate way to do this, and it's far simpler to use the built-in functionality than building a new options panel to handle it. In the process of declaring support for custom headers, you define the height and ...


2

Try adding the global $more variable before you call the_content(). e.g.: <?php global $more; $more = 0; the_content( 'Read More' ); ?> (This is how you enable the "Read More" tag for Pages.)


2

Your code: if( is_page(107) ) return; checks for page and returns nothing on match, effectively it's exactly opposite of what you want. So if you reverse it and put this at start of function: if( !is_page(107) ) return; It will do nothing everywhere, but page 107 where it will proceed to run rest of the function.


2

First line of the codex for get_content: Displays the contents of the current post. This template tag must be within The_Loop. Also, this line: <meta property="og:description" content="<?php string_limit_words(the_content(), 15);" ?> /> would need to get_the_content(), as the_content() will output, and you need to return. <meta ...


2

Query for image attachments would be something like this (taken from Get The Image plugin/extension) with get_children(): $attachments = get_children( array( 'post_parent' => $args['post_id'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => ...


2

I'd personally get into a habit of calling get_term or get_terms, as the category functions are only wrapper functions that in turn call get_term(s) anyway. <?php $queried_category = get_term( get_query_var('cat'), 'category' ); // echo $queried_category->term_id; // The category ID // echo $queried_category->slug; // The category slug // echo ...


2

First, you need to query the child Pages: $pageargs = array( 'numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'page', 'post_parent' => $post->ID ); $childpages = get_posts( $pageargs ); Then, you need to create your custom Loop: foreach ( $childpages as $childpage ) { // Output whatever you ...


2

Check out get_next_post_sort and get_previous_post_sort filters. You can modify the ORDER BY clause to whatever you want (including ). For example, if you want to sort the 'next post' to be the post with the smallest adjacent post ID: function wp28041_get_next_post_sort($where){ return 'ORDER BY ID ASC LIMIT 1'; } add_filter('get_next_post_sort', ...


2

'p' is for querying a post, as opposed to 'page_id' for querying a page. It's documented in the WP_Query codex


2

Yep, wp_trim_words(): <?php $trimmed = wp_trim_words( $text, $num_words = 55, $more = null ); ?> Or in your case: <?php echo apply_filters( 'the_content', wp_trim_words( strip_tags( $post->post_content ), 55 ) ); ?>


2

post_password_required(): whether post requires password and correct password has been provided. <?php if ( post_password_required() ) { echo 'xxx'; } else { echo 'zzz'; }



Only top voted, non community-wiki answers of a minimum length are eligible