• Resolved Jack Reichert

    (@jackreichert)


    How do I find out which page has been set to blog, when wordpress is in CMS mode?

    The background: I am building a theme for someone that wants to use wordpress as a cms. Currently home is set to ‘Home’, and the blog to ‘News & Events’.

    As far as I know, wp_list_pages() only lists pages, which is a problem when the site is configured as it is above if you want to create drop-down menus for the blog categories as well as the pages on the site.

    The solution I came up with was to set echo on wp_list_pages() so that I can dump the output into a variable and then search for the ‘Events</a>‘ and explode the variable there and place in the outputted string for the blog. (wp_list_menu() with echo)

    The only problem with this solution is that now the query to find the page name for the blog is hard coded, if my friend changes the page name (to just “News” for instance), the dropdown menu won’t work anymore.

    So here is my question: How do I find out which page has been set to blog, when wordpress is in CMS mode?

Viewing 7 replies - 1 through 7 (of 7 total)
  • get_option(‘page_on_front’) should give you the ID of the page set as the homepage.

    Thread Starter Jack Reichert

    (@jackreichert)

    Awesome! Thank you!

    Most welcome – thanks for asking a detailed question that made it really easy to help you lol.

    Thread Starter Jack Reichert

    (@jackreichert)

    =) Pleasure.

    Here’s a detailed solution for anyone who wants to know how to make a dropdown menu on wordpress that includes both pages and posts when wordpress is in CMS mode.

    $page_menu = '<ul>'.wp_list_pages('depth=2&sort_column=menu_order&echo=0&title_li=').'</ul>';
    $blog_menu = '<ul>'.wp_list_categories('orderby=ID&echo=0&title_li=').'</ul>';
    $blog_page_id = (int) get_option('page_for_posts');
    $blog_page = get_page($blog_page_id);
    $blog_page_title = $blog_page->post_title.'</a>';
    $menu_pieces = explode($blog_page_title, $page_menu);
    $new_menu = $menu_pieces[0].$blog_page_title.$blog_menu.$menu_pieces[1];
    echo $new_menu;

    Explanation:
    1: Gets the pages formatted as a list
    2: Gets the blog categories formatted as a list
    3: Gets ID for page that is assigned to the blog
    4: Gets info about the page ID
    5: Gets the page title and adds a close link tag so that the blog category menu can be inserted in the correct place
    6: PHP command that breaks up a string into pieces based upon a string that you give it. In this case, the name of the page that is assigned to the blog
    7: Puts the pieces together in the correct order.
    8: echos out the menu. Now CSS it to function as a dropdown!

    Please feel free, all, to comment if you have a more efficient way of doing this. And thanks again for your help Katya!

    What does “CMS Mode” mean?

    Are you referring to WordPress being configured such that the home page is a static page, rather than the blog?

    WordPress is a CMS, and always in “CMS Mode”. ??

    you bumped a two week old resolved thread to be pedantic about terminology?

    good job.

    Yes, actually, because “CMS mode” is not part of the WordPress lexicon.

    Anyone else looking for a resolution to a similar problem may never find this one, because a) they won’t know what “CMS mode” means, and b) they won’t think to search for “CMS mode”.

    Also, inconsistent and/or non-standard terminology has led to more than a few headaches in the WordPress community (see, e.g. “core plugins”).

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Using WordPress As A CMS’ is closed to new replies.