• I’m using the plugin from the codex, “Page to Front”, that makes a Page the front page of the blog.

    I wrote conditional php in my sidebar.php that works great except this front page can’t be targeted using is_home() or is_page() even with it’s ID, Page slug, or title, for example, is_page(’35’)

    My problem is it is “Filed under” the default category, and in my conditional code, I need it not to be included with that, so I’m wanting to code it in an elseif statement. How can I identify it?

Viewing 8 replies - 1 through 8 (of 8 total)
  • I ran into a similar problem. There may be better ways, but what I did to solve it was to define a PHP constant for the Page I’m on within the Page template:

    <?php
    if(get_query_var('name'))
    define('THIS_PAGE', get_query_var('name'));
    else
    define('THIS_PAGE', get_query_var('page_id'));
    ?>

    If the query is to the Page name (i.e. Page slug), it sets my THIS_PAGE constant to it; if the Page is accessed by ID, THIS_PAGE receives that value.

    Then in the sidebar, I do this:

    if(('N' == THIS_PAGE) || ('page-name' == THIS_PAGE ))

    N is to be replaced with the Page ID number, And 'page-name' with the Page slug. You can obviously whittle this down to one of the other, depending the type of permalinks you’re using.

    Thread Starter echozone

    (@echozone)

    Thanks for responding, although I can not get this to work.
    The first part for the Page template doesn’t make complete sense to me, and I tested many variations of it, none of which had any effect.

    I think that the page to front plugin has been overtaken by WP dev. I use home php for my front page. It avoids all this malarkey.

    “The first part for the Page template doesn’t make complete sense to me”

    Add it to page.php (i.e. the Page Template). If the theme does not have this template, make a copy of the index.php, and name that page.php.

    And by ‘add’ I mean edit the template itself in a text editor or through the Theme Editor under Presentation. Place the code somewhere before the get_sidebar() template tag is called.

    Thread Starter echozone

    (@echozone)

    I understood and did all that you explained here, I meant I didn’t completely get the syntax (so I was substituting ‘name’ + ‘page_id’ in various ways). I had tested it with the code both before and inside the loop, and it was always before the get_sidebar.

    I’m wondering if I give up the Page to Front plugin, if a htaccess redirect would work (/blog/ -> /blog/home/) and not break any other part of the blog that references the index.php.

    I’d like your solution to work. I can explain more about my conditional statements if necessary.

    Thread Starter echozone

    (@echozone)

    Further explanation of what I’m doing.
    The blog only has 3 categories. My conditional statement accomplishes this:

    If it’s category n, the sidebar gets recent posts from only that category (using customizable-post-listings plugin).

    All 3 category links remain there hard coded, so it’s like an expanding menu.

    In the same if statement I added, OR if it’s a post in category n (using php from the codex to use in_category outside the loop).

    My main page (using Page to Front plugin) is getting caught by being a post in category 1, + I’m unable to catch it in an elseif statement for is_page, or the final else statement, which shows recent posts from all 3 categories. Everything else works great.

    <?php $post = $wp_query->post; ?>
    <?php if ((is_category(1)) || (in_category('1'))) { ?>

    category 1 link
    get recent posts from category 1
    category 2 link
    category 3 link

    <?php } elseif ((is_category(2)) || (in_category('2'))) { ?>

    category 1 link
    category 2 link
    get recent posts from category 2
    category 3 link

    <?php } elseif ((is_category(3)) || (in_category('3'))) { ?>

    category 1 link
    category 2 link
    category 3 link
    get recent posts from category 3

    <?php } elseif (is_page()) { ?>

    category 1 link
    get recent posts from category 1
    category 2 link
    get recent posts from category 2
    category 3 link
    get recent posts from category 3

    <?php } else { ?>

    category 1 link
    get recent posts from category 1
    category 2 link
    get recent posts from category 2
    category 3 link
    get recent posts from category 3

    Thread Starter echozone

    (@echozone)

    Can I use get_settings(‘home’) which does point to the main page, or hardcode the URL somehow in my elseif statement? I’m not clear on the syntax, if this is possible.

    Thread Starter echozone

    (@echozone)

    Success!
    All I needed to do was put if (is_page()) first!

    I had coded something else (dynamic menu highlighting) and discovered that I could, in fact target the main page with is_page(), so this showed me the problem I was working on was not the issue.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Conditional target of front page “Page to Front”’ is closed to new replies.