Forums

[resolved] if is_pages problem for custom sidebar (3 posts)

  1. gjfo
    Member
    Posted 1 year ago #

    I use Wordpress as a CMS.

    Options/Read with static home page called Home and blog page called News.

    Sidebar.php is widgetized

    On blog page, (News) I have a sidebar like this:

    Pages
    Home
    News
    Products

    Categories
    General

    Recent posts
    Post 3
    Post 2
    Post 1

    On Home page and on Products page I would like to have a simple sidebar like this:

    Home
    News
    Products

    Home page id is 3
    Products page id is 5

    In page.php

    Instead of:
    <?php get_sidebar(); ?>

    I add:

    <?php if (is_page(3) || is_page(5)) {include ('sidebar-2.php'); }
    else {include ('sidebar.php'); }
    ?>

    I create sidebar-2.php like this:

    <div id="left">
    <ul>
    <?php wp_list_pages(); ?>
    </ul>
    </div>

    Sidebar.php begin like that:

    <div id="left">
    <?php if ( !function_exists('dynamic_sidebar')
    || !dynamic_sidebar() ) : ?>
    
    other codes for Archives, categories, etc...
    </div>

    Sidebar of News page goes correctly but I have two problems in other pages.

    Instead of sidebar needed with only:

    Home
    News
    Products

    I have:

    Pages
    Home
    News
    Products

    Also, the content of the page goes in the sidebar under the page list.

    Are you able to tell me what I did wrong and what can I do to fix it?

    Thank You

    gjfo

  2. moshu
    Member
    Posted 1 year ago #

    If you use a template tag - like wp_list_pages - read its documentation.

  3. gjfo
    Member
    Posted 1 year ago #

    Thanks moshu,

    My problems are fixed.

    Information for other users:

    I change

    <ul>
    <?php wp_list_pages(); ?>
    </ul>

    by

    <ul>
    <?php
    wp_list_pages('title_li='); ?>
    </ul>

    The title of the sidebar disappears like I need and the content of the page goes to the right place.

    gjfo

Topic Closed

This topic has been closed to new replies.

About this Topic