Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #15848

    I have included a third-party slider (Slider Pro) with which I have defined a couple of sliders that get displayed instead in the header instead of the built-in slider, based on the Parent-Page ID. It works fine for all pages and posts except for the home page.

    This is the code I use to determine which slider to show:

    function chose_slider(){

    global $post;

    switch (get_post_type()){

    case ‘portfolio’:

    break;

    case ‘page’:

    if($post->post_parent) { //Returns either the ID of the parent page or the page itself if it does not have a parent

    $parent_ID = $post->post_parent;

    } else {

    $parent_ID = get_the_ID($post);

    }

    switch ($parent_ID) { //Returns the correct slider for each top-level page

    case 1827: //About us

    echo slider_pro(4);

    break;

    case 1681: //Climate Protection

    echo slider_pro(5);

    break;

    (…)

    }

    case ‘post’:

    echo slider_pro(1);

    }

    }

    However, on the home-page get_post_type() always returns ‘post’ and get_the_ID() returns the ID of the latest blog post. Following that, the wrong slider is displayed.

    Can you help me?

    #89236

    Hi,

    is_home() or is_front_page() depending on your setup is used to identify the main page. You can read more about WordPress conditional tags here -> http://codex.wordpress.org/Conditional_Tags

    or you can look at the url in backend when you edit the homepage, to get the page ID of whatever page you declared as your homepage, and then add another case block for that id , just like what you are doing with 1827.

    Thanks,

    Nick

    #89237

    Thanks for the quick reply, there was a misunderstanding though: the problem was not to actually know the front page ID, but get_post_type() and get_the_ID() returned wrong results for the front page.

    However, I solved the problem now, just in case somebody has the same issue, here is the reason:

    I used the theme options to set the front page to a static page. In the wordpress settings (Settings>Readings), however, the front page was still set to the most recent post. Although that option seems to have been superimposed by the theme settings, the two functions mentioned above did still return the results for the first post. Setting the wordpress front page to the same page as the theme options solved the issue.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Page ID of front page’ is closed to new replies.