How to get post object on blog template

I have a big issue on catching attributes from global $post_object in a page template file.

I have a Template Name: Blog Page which is template-blog.php

Read More

On that page I use the current page permalink to load more posts using Ajax.

So basically I do Ajax Requests in the same URL, and on template-blog.php is a condition if $_POST['load_more'] is true, if yes than return a portion of posts.

My problem is I cant get the page ID or page permalink using the $post variable when this page is set as the Blog Page on WordPress (Settings-Reading-Posts Page).

When the template-blog.php is set-up as the posts page, the $post variable is the first post which $wp_query has on it’s post’s array.

I hope I was clear enough.

Description

On normal page State the Permalink is the Page Permalink:

get_header();
$link = get_the_permalink();

But when this page is set-up as Posts Page the Permalink is the Permalink of the first posts on $wp_query:

get_header();
$link = get_the_permalink();

Related posts

Leave a Reply

1 comment