Result of get_permalink(0); - php

I'm new to wordpress and I'm following a tutorial right now but I don't understand wordpresses behaviour. I'm trying to change the title of a sidebar which lists the parentpage and it's childpages, this works fine but I don't understand why $parentID = wp_get_post_parent_id(get_the_ID()); echo get_permalink($parentID); works even on the parent page, I echoed the result on the parent page and it returns 0 since the parent page doesnt have a parent, so why does this still work? Why does get_permalink(0); get me to the parent page if I press the button?

get_permalink()is the function that gives you the link to the post/page inside the loop you are currently. Since you are not having parent page for the current page get_permalink is not able to get you to the parent page as nothing exist so in this case it will rediret you to the same page.

Related

Insert variable into Wordpress page title for individual page

I have a photo gallery page that is using a single page in Wordpress.
The gallery display is dynamic, and relies on a URL parameter. The parameter itself is an integer of the relating wordpress page ID. (as that's the page it's about).
Here is an example of a gallery URL:
http://www.bellavou.co.uk/gallery/?pid=238
For SEO purposes, I'm trying to get away from every possible Gallery URL combination to have the page title 'Gallery', as is set in the Wordpress page settings.
I've been trying this, which has been mentioned a few times:
function assignPageTitle(){
return "Title goes here";
}
add_filter('wp_title', 'assignPageTitle');
But as I'm also using Yoast SEO plugin, I think this is over-writing it (even though I uncheck 'Force title rewrite', and keep the page title field blank). Not sure why the above function doesn't seem to work.
Within the gallery page, I'm able to show the h1 title properly, passing PHP Variables into the code, but I want to do the same to the page title, but in a way that can be done directly on the page template.
Why is it that whenever I post a question, I seem to find the answer very soon afterwards?
I read a post saying that it helps to put a wp_title function before the wp_header call, which is what I tried, and that seems to work fine.
I can edit the page title just for an individual page using the PHP page template, and using this:
$procedure = isset($_GET['pid']) ? $_GET['pid'] : '';
add_filter( 'wp_title', 'wp_title_gallery', 100 );
function wp_title_gallery($title) {
global $procedure;
if(!$procedure) {
$title = the_title();
} else {
$title = the_title(get_the_title($procedure).'&nbsp');
}
return $title;
}
get_header();
$procedure gets the URL parameter, and then the function takes that ID, and gets the associated page from it, and then prints the title of the page, into the page title hook. Lastly, the WP header is called.
(Just incase anyone comes here looking for a solution)

Contao: Frontend - Get theme section of another page - not the current page

I would need to reach a custom section by page id (or PageModel Object), but I don't find a way to get the FrontendTemplate. I would like to use it in a dropdown navigation to echo a custom section of the hovered (parent) page.
If somebody will search for, the answer is:
<?php
$articles = \ArticleModel::findPublishedByPidAndColumn($id, $column_name);
echo static::getArticle($articles[0]); // for ex. the first article
?>

Show parent page content on a child page - Wordpress

I have been trying for the past couple days to show the content from a parent page on a child page, but I wasn’t able to do so. Most of the codes I found were to show child page content on a parent page and had a loop.
What I’m looking to do is just grab the text from the parent page and display it on the child page, no loops needed.
Any help is appreciated.
Thank you.
use post_parent
<?php
$parent_id = $post->post_parent;
$parent_post = get_post($parent_id);
$parent_content = $parent_post->post_content;
echo $parent_content;
?>
Don't forget to use wp_reset_query(); in order to get the current page content.

Why can I see the variable in the URL but the variable contains NULL when using GET

I am using a WordPress child theme and a custom page template. A separate folder in the child theme directory connects to an external database outside of this WordPress install. All database connections are good!
I am having a problem reading a 'test' variable passed from a link to another PHP page. Both pages exist in WordPress but each page are using a different page template - passing a variable between page templates!!
The HTML and PHP code from the first template (Wordpress Page) sends on link click to the other
View Photos
The destination URL reads: websiteurl.co.uk/?page_id=93?test=162
To see if the variable is being passed correctly before continuing I dumped the variable, however the variable contents displayed NULL
<?php var_dump(count($_GET['test'])); var_dump($_GET['test']); ?>
I have also tried
<?php var_dump(count($_POST['test'])); var_dump($_POST['test']); ?>
But the output is
int(0) NULL
Why can I see the variable in the URL but the variable contains NULL when using GET? All research seems to suggest this should be fine, or is it the way WordPress handles the URL?
Hope someone can point me in the right direction!
Thanks in advance
Your URL needs to be as
websiteurl.co.uk/?page_id=93&test=162

Wordpress nulling PHP on one page, not on others?

I'm using this script to call a link to the parent page inside one of it's children pages:
<?php
$this_page = get_post($id);
$parent_id = $this_page->post_parent;
if ($parent_id) {
$parent = get_page($parent_id);
echo 'Return to '.get_the_title($parent->ID).'';}
?>
This sample works just fine here:
http://www.energytoolsint.com/clean-sweep/parent-test-call/
But won't parse here?
http://www.energytoolsint.com/healthcare-practitioners/
Same page template, one renders, the other doesn't.
Judging by the URL, that's because energytoolsint.com/healthcare-practitioners is a parent page. Granted, you could have changed the permalink, but the URL suggests it doesn't have a parent, hence the null value.
Go to the page in dashboard. Look on the far right under the publish date.

Categories