Forums

Content in the Sidebar on Pages only? (5 posts)

  1. koko.pelli
    Member
    Posted 3 years ago #

    Hi everyone,

    I have set up a site with multiple pages and the blog section is set to a specific internal page as a news section.

    What I am trying to do is have a snippet of the first news blog post appearing on the sidebar in every page on the site except the internal blog page.

    I think I need some kind of if/else statement but not sure of the tags I need to use:

    Have tried:


    <?php if (is_blog()) { ?>
    <p>Test</p>
    <?php } else { ?>
    <?php require('wp-blog-header.php');
    query_posts('showposts=1');
    while (have_posts()) : the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <?php the_excerpt('…'); ?>
    <?php endwhile; ?>
    <?php } ?>

    But no joy with this.

    Can anyone help?

  2. stvwlf
    Member
    Posted 3 years ago #

    what is the full URL of the page your blog is displaying on?

  3. koko.pelli
    Member
    Posted 3 years ago #

    It's local at the moment, but the URL is:

    http://localserver/news-events/

  4. stvwlf
    Member
    Posted 3 years ago #

    this will probably work

    <?php if (is_page('news-events')) { ?>
      <p>Test</p>
    <?php } else {
      $newsposts = new WP_Query();
      $newsposts->query('showposts=1');
      while ($newsposts->have_posts()) : $newsposts->the_post(); ?>
        <h2><?php the_title(); ?></h2>
        <?php the_excerpt();
      endwhile;
    } ?>

    if you are doing this within WordPress you do not need
    <?php require('wp-blog-header.php');
    that is already loaded

  5. koko.pelli
    Member
    Posted 3 years ago #

    Thank you - tried it but no joy :(

Topic Closed

This topic has been closed to new replies.

About this Topic