0

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?

1 Answer 1

0

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.

7
  • 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
    Commented Jul 8, 2012 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 ? Commented Jul 8, 2012 at 18:58
  • Hi Dane - on all but the startpage.
    – ad2003
    Commented Jul 9, 2012 at 15:09
  • Did you make sure you have the ! in front of the conditional? Should be !is_page('startpage'); or !is_front_page(); Commented Jul 10, 2012 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
    Commented Jul 10, 2012 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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