0

I've been trying to fix this for weeks now.

I want to display a certain kind of posts on all my pages at the top. The code should be located in the header.php. It will display sponsors, and the post will only be showing the featured image.

To do this I've tried using Blog-in-Blog and Category List Posts. Both great plug-ins to display a certain category. I've used do_shortcode to display the list, because originally the posts can only be displayed through the_content(); of a page using [blog-in-blog id=7] or whatever.

My problem is that it will display the posts on ALL pages on my website, except for the front-page. I really can't understand this. The "Category List Posts"-plugin simply doesn't display anything, but the "Blog-in-Blog"-plugin displays an error message:

ERROR: Blog-in-Blog shortcodes can only be used in pages, not posts.

But it's not a post. It's a page, right?

This is part of my header.php-file (if that could help):

<body <?php body_class(); ?>>

<header id="header">
<!-- Content -->
</header>

<div id="sponsors">
    <div class="wrap">
        <h1><span>Our Corporate/Business Sponsors</span></h1>
        <?php echo do_shortcode("[catlist content=yes title_class=header-title title_tag=h2 id=17 thumbnail=yes thumbnail_size=50,50 numberposts=20]"); ?>
    </div>
</div>
6
  • You'll probably get help in the plugin's own support forum
    – RRikesh
    Apr 6, 2013 at 18:20
  • I've gone through all the support pages and googled like a madman with no results or fixes to be found. Apr 6, 2013 at 18:22
  • You tried asking there? The plugin author will be the best one to answer you.
    – RRikesh
    Apr 6, 2013 at 18:22
  • The plugin author is inactive, unfortunately. Apr 6, 2013 at 18:23
  • 2
    if you look at the blog in blog code, you'll see it checks is_page(), so anything not explicitly a page will return that error (home, front page, an archive, a tag, a category, etc..). however, if you're doing this by editing a template, it somewhat defeats the purpose of using a shortcode. just skip the whole plugin thing and query for what you want directly via WP_Query and output it yourself.
    – Milo
    Apr 6, 2013 at 18:31

1 Answer 1

0

You can do this easily with a custom query. Try something like this (I haven't tested this code, but it should be fine): (EDIT: Changed below to "get_the_post_thumbnail", also added $post->ID)

<ul>
 <?php 
  $args = array(
   'cat' => '17',
   'posts_per_page'=>20
   );
  $sponsors_query = new WP_Query( $args );

  while ( $sponsors_query->have_posts() ) : $sponsors_query->the_post();
    echo '<li>' . get_the_post_thumbnail($post->ID, array(50,50)) . '</li>';
  endwhile;

  wp_reset_postdata();
 ?>
</ul>
19
  • This code displays the same one image 8 times (the amount of posts I have in category 17), and the images is from a different category. Also, it displays on ALL the pages, but not my front-page/homepage. It doesn't make sense. Apr 6, 2013 at 18:50
  • 2
    You're passing the size argument as the first parameter of get_the_post_thumbnail, when it should be the second. Either use the_post_thumbnail( array(50,50) ); or get_the_post_thumbnail( $post->ID, array(50,50) ); Apr 6, 2013 at 18:50
  • @JohannesPille fixed the thumbnail. Now correct size and corresponding image. Thanks! But it's still not displayed on the front-page. Apr 6, 2013 at 18:52
  • @FrederickAndersen - are you sure the front page template calls the header file you've put this in?
    – Milo
    Apr 6, 2013 at 18:53
  • Yes! It calls it. It displays everything else from it. It also displayed the error message from the Blog-in-Blog-plugin, so it does call it. Apr 6, 2013 at 18:54

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.