Tag Info

Hot answers tagged

8

Although I'm also curious as to why you'd want to do this, and would probably suggest using a custom post type instead, this would probably work (actually works for any single post type except pages and attachments): add_action( 'pre_get_posts', 'wpse44983_single_post_404' ); function wpse44983_single_post_404( $query ) { if ( $query->is_main_query() ...


8

You can use the following instead, if (is_singular('post')) { //your code here... } Where by is_singular is the WordPress API conditional function for testing for the existence of a post type. You can also pass an array of post types if you wish. http://codex.wordpress.org/Function_Reference/is_singular


6

There's nothing stopping you using AJAX for a singlepage website that loads in other pages dynamically rather than going to a whole new page. I would advise you build the site without the AJAX and then add AJAX on top so that everything degrades gracefully should an error occur or if javascript is turned off. So assuming that you've now got a site that ...


6

You don't want a post to be the front page, you want a custom post type entry to be the front page. Now that we have the terminology right, yes it's possible. A client once asked me to do the exact same thing. They had a custom post type they needed displayed on the front page. Doing so was as simple as adding a filter to allow them to select a "stack" ...


6

According to the WordPress conditional docs it should be: if(is_singular( 'video' ) ){ // do conditional stuff } else{ //do other stuff } Also if you want a blank page or no content to show when the CPT is not video you don't really need the else so you could omit it. You could ALSO do something like: if(!is_singular( 'video' ) ){ // do ...


5

Well, for anyone else looking to solve a similar problem, I found this post, and it led me in the right direction: http://wordpress.org/support/topic/pagination-on-singlephp-causing-301-redirect?replies=9. I added this snippet of code to my functions.php, and I can paginate in custom queries without issue on single.php now. I don't know enough about it to ...


5

You could try something like (http://codex.wordpress.org/Function_Reference/get_post_type) : to check if it's not a specific post-type : if ( is_single() && 'portfolio' != get_post_type() ) { // DO STUFF } or to check if it's a post and not a post-type : if ( is_single() && 'post' == get_post_type() ) { // DO STUFF }


5

Visit the permalinks page (which will flush it) and check again. WordPress probably just needs to be nudged to recognize your addition to the hierarchy.


4

I used this little trick to obtain the taxonomy image given the ID of the term: <?php $images = get_option('taxonomy_image_plugin'); $img_url = wp_get_attachment_url( $images[$term_id] ); ?>


4

is_single() returns TRUE or FALSE, not a string. Additionally, you can test for a specific post with is_single() function by putting the post slug into the function call: if ( is_single( 'your-post-slug' ) ) { # do something } If you want to test for the proper post type use: if ( is_singular() and 'your-post-type' === get_post_type() ) or just: ...


4

get_ancestors() should do what you need: So, you should do something like this: $ancestors = get_ancestors($term_id, 'projects_category)


4

For the templates WordPress uses, please always refer to Template hierarchy scheme in the Codex. As you can see there, single-{$posttype}-{$slug}.php does not exist, there is only single-{$posttype}.php. To do what you want, have a look at the filter 'single_template': add_filter( 'single_template', function( $template ) { global $post; if ( ...


3

If I understand well you want to show the last post (one post) from one of the 3 post types you have, using a dynamic url like http://example.com/latest. First of all lets add a filter to 'do_parse_request' filter: add_filter( 'do_parse_request', function( $bool, WP $wp ) { $home_path = trim( parse_url( home_url(), PHP_URL_PATH ), '/' ); $path = ...


3

Use the post thumbnail for the single blog pages too. You can use the add_image_size() function to create an additional image size that is displayed on the blog posts. add_image_size('single-post-image', 650, 250, true); // name, width, height, crop mode Then in single.php the_post_thumbnail('image-size'); Simply place the first function in your ...


3

Unless you have added the functionality with a plugin or custom code, Pages are not placed in Categories. Pages are organized with Parent Pages and Children Pages. This is why (I suspect) in_category() does not work in page.php The following code in functions.php will add categories to Pages. /** * Add categories to Pages. * from ...


3

Just check for the global $numpages variable: <?php global $numpages; if ( is_singular() && $numpages > 1 ) { // This is a single post // and has more than one page; // Do something. } ?>


3

the function get_the_tags() does for a single post, what get_tags() does for the site.


3

There are a number of template filters you can use to alter the template hierarchy. Have a look at the template hierarchy page at the filters and example provided. Here's a modified version of the example that uses single_template. It checks for a specific custom post type and loads the theme's page.php template if it exists: function ...


3

This should help, if you need more info: http://codex.wordpress.org/Template_Hierarchy Simply put, Wordpress looks for template files in the following order for single posts: single-{post_type}.php, single.php, index.php. If you want to override the standard single.php file, that's how (for a custom post type only, as you're using)


3

You can use the filter hook for 'single_template'. Create single-cat1.php, single-cat2.php and single-cat3.php (cat1, cat2 and cat3 are the category names should be replaced by your category names) function template_change( $template ){ if( is_single() && in_category('cat1') ){ $templates = array("single-cat1.php"); } elseif( ...


3

While much of comments implementation became simpler in modern WP versions, it still isn't quite make-comments-happen button. You will need to put together this part of template, most of related functionality is handled by: wp_list_comments() comment_form() Check native WP themes for complete start to end implementation, although they tend to be a ...


3

I don't think get_categories() is the best option for you in this case because it returns a string with all the categories listed as anchor tags, fine for displaying, but not great for figuring out in code what the categories are. Ok, so the first thing you need to do is grab the product/post object for the current page if you don't already have it: global ...


3

There are some global variables available (or not) to detect the current page number: if ( empty ( $GLOBALS['multipage'] ) or $GLOBALS['numpages'] === $GLOBALS['page'] ) echo '<a id="lastPageLink" href="#comment">comment</a>'; The best way to understand what they do is a look at the internals of wp_link_pages(). (bool) ...


3

init is too early (it happens before the main query), use the action template_redirect instead. And for the ID use get_the_ID(). Example: if ( is_singular() ) setcookie( get_the_ID(), 'visited',time() + ( DAY_IN_SECONDS * 31 ) );


3

Per a comment, the problem was due to the use of query_posts which clobbers the main query. Please don't use query_posts. It should be noted that using this to replace the main query on a page can increase page loading times, in worst case scenarios more than doubling the amount of work needed or more. While easy to use, the function is also prone ...


3

You can use a shortcode or the_content filter. I think the_content filter is better because your don't introduce any string in your post, so the content can be exported and used in another platforms if needed. For emxample, for show a block of adsense after the first parragraph: add_filter( 'the_content', 'tbn_ads_inside_content' ); function ...


3

As the WordPress Codex for have_posts points out: As a side effect, have_posts starts, steps through, or resets The Loop. At the end of the loop, have_posts returns 0 after calling rewind_posts. Looking at the source as it stands today: along with calling rewind_posts() it also fires the loop_end action (which plugins may rely upon) as well as set a ...


2

You should have to look at what the codex says about previous_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) and next_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) Both have the same parameters, the first parameter $format is the important one to have ...


2

Queries ofcourse. It's faster... But in this case just please delete you wp site and start with something faster... here is my superfast framework for you... <?php /*Your bunny wrote */ I did tests, 0.0000001 runtime vs WP usually 0.7-2.8 Sarcasm off P/S/ This question have no sence since using direct queries and output of the variables isn't use ...


2

Ok, So, this is a two part question, part #1: What I would like to do is count the number of posts in a category and use the next_post_link and previous_post_link link to navigate through them, then display a count. What I did to fix this issue was install the Smarter Navigation plugin Then use the following for my Previous and Next Links: ...



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