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

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
?>

Related

Display custom field from parent page

On a child page x, i want to output a custom field from the parent page
<?php the_field('imagecategory'); ?>
The child page can also have this field (but i dont want to grab that)
so what i want is:
On the child page, grab the parent page id. And for that specific page show the output of the code
<?php the_field('imagecategory'); ?>
I asume i need to grab the parent id with $post->post_parent;, but i got no idea how to tell the code to grab that custom field for that specific page :(
Aparently you are using Advanced Custom Fields (ACF) plugin right? If yes, you must to get your custom page where you set your custom field before to show it on a different page, something like this:
<?php $mypage = get_page_by_title('my page'); ?>
<p><?php the_field('custom_field', $mypage); ?></p>
I hope it helps.

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.

Conditionally display menu for page type in Wordpress

I am relatively unfamiliar with Wordpress and I am creating a custom theme for a client. I would like to either display or remove the main menu depending on the page type. I have researched several options like removing the navigation from header.php and referencing it separately and also making the menu conditional which is preferable.
I have a custom page type in my theme called 'landing page' on which I would like the menu to be never be displayed, though it will be on every other page. Ultimately there will be a lot of these and I would rather I didn't have to intervene.
I would rather not duplicate my header.php file but I can only find reference to displaying the menu conditionally like below by page name or ID which seems ridiculous.
<?php
if (is_page('contact')){
<?php include(TEMPLATEPATH.'/headerA.php'); ?>
}
elseif (is_page('gallery')){
<?php include(TEMPLATEPATH.'/headerB.php'); ?>
}
else {
<?php include(TEMPLATEPATH.'/headerA.php'); ?>
}
?>
Rather than including files as above, I will put the whole thing into my header and just make the navigation conditional. Does anyone know how I should approach this using my custom page type landing page rather than by page name so every page created with that type will never have a menu?
Thanks
Are you talking about a Custom Post Type (CPT) or a page called landing-page?
They are completely different. See http://codex.wordpress.org/Post_Types
In any event, this will work for a custom post type or a page:
if ( !is_singular( 'custom-post-type-name-or-page-slug-here' ) ) {
get_template_part('menu');
}
It says: "If this page is not a single page or a CPT, load the file menu.php from the theme folder."
See also http://codex.wordpress.org/Include_Tags:
The get_template_part() tag includes the file {slug}.php or
{slug}-{name}.php from your current theme's directory, a custom
Include Tags other than header, sidebar, footer.

Wordpress - output automated secondary navigation on posts as well as pages

I currently have a script that outputs a secondary navigation based on the site menus, however I can't think of anyway to link a post to a page so that the posts can still show a secondary navigation, is this even possible? Here is the current code i'm using to output my secondary navigation:
<?php
$secondAncestor = count($post->ancestors) -1; //figure out what level of navigation we are on, subtract one because we don't want to consider the top-level
if($post->post_parent!=0) //if the page is not a top-level category
{
echo '<nav><h2 class="widgettitle">In this section:</h2><ul class="secondary-nav"><li class="sidebarlist">';
//the following lists children of second level ancestor of the current page.
wp_list_pages("title_li=&child_of=".$post->ancestors[$secondAncestor]."& sort_column=menu_order&echo=1");
echo '</li>';
}
else //if the page is a top-level category
{
//listing only the child pages of the current section
$children= wp_list_pages("title_li=&child_of=".$post->ID."& sort_column=menu_order&echo=0");
if($children) //this will stop it from displaying a section heading if there are no elements in the section (for example on the home page)
{
echo '<nav><h2 class="widgettitle">In this section:</h2><ul class="secondary-nav"><li>';
echo $children;
echo '</li>';
}
}
echo '</ul></nav>';
?>
Pages are heirarchical, so they can have parents and children.
Posts are flat, and related by categories and tags.
In order to relate a post to a page, I think you're going to need to use a custom field on your posts. You could call it Parent Page ID, and then in your sidebar code, add a custom query that checks for posts whose Parent Page ID = the current page's id.
Check out Flexi Pages Widget. This will add a highly configurable subpage menu to your sidebar, which you can embed on posts & pages.

wordpress plugin admin menu

I am trying to create a wordpress plugin admin menu. The problem that I am running into is with the menus. I am trying to add a page in the admin without actually adding the menu link. So for example I want to have a menu called test then I want to have some extra pages but I don't want physical links to them because they are only going to be used when there is an id to pass to them. is this possible and if so please someone explain because i can't seem to figure it out.
Yes. In your callback function for the admin page, just write out different sections and use conditional checks to display the right content. Then, under the page's title, add a <ul> with the class subsubsub containing the links to take the user to the right place. Something like this:
function my_awesome_admin_page(){
echo '<h2>My Title</h2>';
echo '<ul class="subsubsub"> <li>Foo</li> <li>Bar</li> </ul>';
if($_GET['foo'] != 'bar'){
//You're on the first page
} else {
//You're on the second page
}
}
I forget what the class is to signify the current subpage, but you can take a look on the 'Add Plugin' admin page. I think it's selected.

Categories