Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a website which shows alle posts from my wordpress on the startpage. thanks to Stephen Harris who helped me with this code I put in the functions.php:

add_action('pre_get_posts','wpse57309_alter_front_page_query');
function wpse57309_alter_front_page_query( $query ){
     if( $query->is_main_query() && is_front_page() ){
         if( !$query->get('post_type') ){
             //post type is not set, the default will be an array of them:
             $query->set('post_type',array( 'movies', 'music', 'featued'));
         }
     }
}

Now I have another problem: I am getting the titles for each section by using this code here:

<?php wp_reset_query(); ?>
<?php echo $post->post_type; ?>

in between h2 tags - but now on Startpage I get different names of the post type - but I'd like to have just: "Home" as Title... I tried it with is_home() and with is_front_page() but I had no luck.

Also the "post_type" is set to one specific on this page.

I have built in a filter which filters on click the posts using a &style=soul

but on startpage its now always one specific post_type. I guess its the last post's post_type...

Maybe someone has a hint?

share|improve this question
add comment

1 Answer 1

I think perhaps what you want is either

<?php if ( !is_front_page() ) : ?>
   <h2>
      <?php wp_reset_query(); ?>
      <?php echo $post->post_type; ?>
   </h2>
<?php endif; ?>

if you've done a custom front page that shows the blog posts, or

<?php if ( !is_home() ) : ?>
   <h2>
      <?php wp_reset_query();
      echo $post->post_type; ?>
   </h2>
<?php endif; ?>

if your front page is a static page and the post list is on a blog page or you have the vanilla setup.

This will output the post type heading on all pages that run the template except the home page or the front page.

or

<?php if ( is_page('my-page-slug') ) : ?>
   <h2>
      <?php wp_reset_query();
      echo $post->post_type; ?>
   </h2>
<?php endif; ?>

if you have this on some other specific page.

share|improve this answer
    
Hello Dane, thanks for the reply. I have tried it with the conditional tags, but than it doesn#t show anything. Somehow wordpress seems to "think" that it is always frontpage or home.... –  ad2003 Jul 8 '12 at 16:58
    
Well, WordPress doesn't think you are always on the home page, either there is an error in the code, or you are expecting something different that what the code you are using is doing. You are wanting the $post->post_type; to show up on ? one page : all BUT one page ? –  Dane Morgan Jul 8 '12 at 18:58
    
Hi Dane - on all but the startpage. –  ad2003 Jul 9 '12 at 15:09
    
Did you make sure you have the ! in front of the conditional? Should be !is_page('startpage'); or !is_front_page(); –  Dane Morgan Jul 10 '12 at 1:05
    
Hi Dane, yes I put ! in front. The problem is the code in the functions php I guess - which tells wordpress to "query" posts from these custom post types, so of course wordpress can't really understand, what I want. is_home and is_front_page don't work - because wordpress uses the index. Maybe I'd need another file? –  ad2003 Jul 10 '12 at 10:23
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.