WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] checking if page is the wordpress default blog landing page (35 posts)

  1. justinblayney
    Member
    Posted 1 year ago #

    Hello,
    I am trying to test if a page is the default wordpress Blog landing page..

    i created a page named blog and this is different than the home page. The $post->ID for blog is 13

    usually i could test for $post->ID, but because it has blog articles, the post ID becomes the ID the the first article in the list instead of 13...

    Also, i only want to check for this page, if it is a category, article, author,etc.. listing I do not want these pages.. i only want the initial page for the blog

  2. justinblayney
    Member
    Posted 1 year ago #

    Hi Josh, thanks for the help... i think i am missing something though...

    if (is_page('creative-blog')) { echo "blog";} else { echo"not blog"; }

    this always echos "not blog", what is wrong with my if statement

    (the slug is actually named creative-blog

  3. What is it exactly you are wanting to do?

    Are you making a page template and running this code from the template?

  4. justinblayney
    Member
    Posted 1 year ago #

    So i tried some other code

    $post = get_post($post->ID);
    $slug = $post->post_name;
    echo $slug;
    if ( $slug == "creative-blog") { echo "blog";} else { echo"not blog"; }

    the problem is slug variable always changes to the top article in the list , even thought the URL reads /creative-blog

    What i am doing is this...

    the Blog landing page will have a very specific style including header and menu..... the other pages (categories, tags, single, etc...) will have a different style..

    So i need to isolate the very first page people land on when they click my blog link, the page i designated in dashboard - settings - reading - Posts page:

  5. justinblayney
    Member
    Posted 1 year ago #

    i am running this code is the header.php and functions page

  6. What is the url to that landing page?

  7. justinblayney
    Member
    Posted 1 year ago #

    /creative-blog

  8. I mean, do you have it live?

  9. justinblayney
    Member
    Posted 1 year ago #

    http://www.jarcreative.com/wordpress/creative-blog/

    i am dumping my variable in the top left corner..

    you will notice the SLUG echo is correct for every page except Blog, on blog it turns into the first article

  10. Let's try this:

    if(is_front_page()) {

  11. justinblayney
    Member
    Posted 1 year ago #

    this works fine.. but it isnt the front page so no good to me

  12. How do you have your settings configured of what page to display be default?

    settings -> general -> reading

  13. Why don't you just make a page template... and assign that as your blog main page?

    This will give the page an ID... which can then be used for conditional formatting.

  14. justinblayney
    Member
    Posted 1 year ago #

    i have blog choosen

  15. justinblayney
    Member
    Posted 1 year ago #

    ok, i copied and pasted index.php, named it blog-landing page.. and gave it template tag

    i wnet into pages - blog and told choosen that as my template..

    makes no difference..

    this is a huge hole in wordpress, the blog landing page does not seem to exist as a actual page

  16. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    the default wordpress Blog landing page

    do you mean the 'posts page' ?

    is_home()

    http://codex.wordpress.org/Conditional_Tags#The_Main_Page

  17. Okay... I'll have to look into this a little bit.

    I see what you are doing now...

    Once again.. just for clarification... what are your settings -> reading for front page displays?

    Are you showing latest posts or static page? If static, is it a "front page" or a "posts page"? And, what is the name in the dropdown?

    EDIT: Alchymyth... our Savior!!

  18. I guess that worked for him ;)

    Thanks for your help, Alchymyth!! I wish I could "pick your brain" for a few days!!

  19. justinblayney
    Member
    Posted 1 year ago #

    Hi guys.. Lol, We are way beyond that simple solution

    The home page is static and home is selected in drop down

    Posts page had blog selected ..,

  20. justinblayney
    Member
    Posted 1 year ago #

    Trust, I have the basics covered, this apparently is a very advanced problem..

  21. is_home()
     When the main blog page is being displayed. This is the page which shows the time based blog content of your site, so if you've set a static Page for the Front Page (see below), then this will only be true on the Page which you set as the "Posts page" in Administration > Settings > Reading.

    Sounds like exactly what you are trying to do??

    Are you sure you have the settings correct in the admin panel for "front page displays"?

  22. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    this apparently is a very advanced problem..

    you might possibly need to try to explain in other words or in more datail what exactly you are trying to do.

    usually i could test for $post->ID, but because it has blog articles, the post ID becomes the ID the the first article in the list instead of 13...

    to get the 'posts page' ID if you have set a static front page and a posts page, you can use:

    get_option('page_for_posts')

    i only want to check for this page, if it is a category, article, author,etc.. listing I do not want these pages.. i only want the initial page for the blog

    I am not sure if I understand what you are trying to do.

    the 'posts page' usually uses index.php; review the template hierarchy: http://codex.wordpress.org/Template_Hierarchy

    have you tried to do this with the corresponding conditional tags: http://codex.wordpress.org/Conditional_Tags

  23. justinblayney
    Member
    Posted 1 year ago #

    Hi guys.. I am positive I have my settings correct.. If you click on the logo in top corner you are brought to the home page.. It has a very large gradient under the banner taller than the other pages... Exactly as the home page template was designed and chosen in reading by me.

    Yes index,PHP is the blog home page, unfortunately I want to detect this is the header file.

    The posts page is set to blog in reading

    It is very simple.. Click any links, you will notice that my echo is top corner matches the page... EXCEPT for blog.. Which instead echoes the slug of the first post.. I need it to detect the URL jarcreative.com/wordpress/creative-blog

  24. justinblayney
    Member
    Posted 1 year ago #

    The disconnect is this..

    When blog is not home page..
    The actual URL as seen, typed and displayed in the browser address bar
    Is Not the slug.. the slug is the most recent blog post

    Therefor when checking for the page Id or slug the page "blog", you Instead get page id and slug if most recent post

  25. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    this should output the posts page's slug:

    if( is_home() && get_option('page_for_posts') ) echo get_page(get_option('page_for_posts'))->post_name;
  26. justinblayney
    Member
    Posted 1 year ago #

    I have done that already.. Look in top left corner

  27. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    what code are you using to output the slug in the top left corner?

  28. justinblayney
    Member
    Posted 1 year ago #

    $post = get_post($post->ID);
    $slug = $post->post_name;
    echo $slug;
    if ( $slug == "creative-blog") { echo "blog";} else { echo"not blog"; }

  29. justinblayney
    Member
    Posted 1 year ago #

    I have been on my iPhone since 5:30.. I won't be able to try any code until the morning...

Topic Closed

This topic has been closed to new replies.

About this Topic