• Hello

    Not sure if this is correct forum….

    but…

    I have registered a side bar which is working and when I just pull it in it works, however, I want to only pull it in on one page…

    So I have used the following code…

    <?php
    
    if(is_page('news'))
    	
    {
    
    if ( is_active_sidebar('news-page-image')) { 	
    dynamic_sidebar('news-page-image'); 
    }
    
    }
    else {
    	
    }
    
    ?>
    
    

    If I take out the if is page ‘news’ bit it shows on every page…so the sidebar bit is working…just not the page slug…the news page has the slug ‘news’ ..it is the posts page in Louis wordpress theme.

    Any ideas much appreciated

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Kanger

    (@kanger)

    Also forgot to mention…

    on the news page in dashboard there is no editor box like all the other pages have…it is just page title and slug, no editor…not sure why that is or if it may be causing the issue.

    Moderator bcworkz

    (@bcworkz)

    It may be the loop driving the posts list has corrupted some query properties that is_page() relies on. Try calling wp_reset_query() before calling is_page(). This will restore the main query to its normal state.

    If that doesn’t help, it may be because of the designation as the posts listing page. When a page is so designated, it’s not really a page any more. That is why the edit box disappears on the edit screen (it’s normal in this situation). It’s more like the template for an archive listing now. I think you should get the main query object ID after calling wp_reset_query() by calling get_queried_object_id().

    I think it will still return the news page ID. Use that as the conditional comparison. If that fails, try getting the entire queried object with get_queried_object(). print_r the object for examination. I would expect there would be something in the object that is unique that distinguishes it from any other query. Use that for the conditional comparison.

    Thread Starter Kanger

    (@kanger)

    Thank you…I tried that to no avail…think it may have been my dodgy coding, but gave me the idea to use url to check if it’s the page I’m after so I ended up doing this….

    `$url = ‘https://&#8217; . $_SERVER[‘SERVER_NAME’] . $_SERVER[‘REQUEST_URI’];

    if (strpos($url,’news/’) !== false) {
    if ( is_active_sidebar(‘news-page-image’)) {
    dynamic_sidebar(‘news-page-image’);
    }

    }
    else {

    }`

    • This reply was modified 7 years, 10 months ago by Kanger.
    • This reply was modified 7 years, 10 months ago by Kanger.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Page Slug not working’ is closed to new replies.