Wordpress - Display Content on page and its children - php

I am trying to implement a submenu into my page.php. It shall be dynamic so the different pages of my site have different submenus displayed on a certain place.
This is what I got so far:
<?php if (is_page(unternehmen || $post->post_parent==unternehmen)): ?> <!-- Unternehmen /postID 553 -->
<?php wp_nav_menu( array('menu' => 'Unternehmen Submenu' )); ?>
<?php endif; ?>
But with this solution the submenu here called "Unternehmen Submenu" will be displayed on every page that uses the page.php. I need a solution that displays the menu only on the respective page defined in the if-statement and its children. The best solution would be if the code fetches the main menu into this. It's an easy menu with one sublevel.
I searched for this specific problem here but didn't found a solution.

Related

Adding content to wordpress page

So, i finally got my css and js scripts to load on WP
Now there is but one thing i need to get done.
i have my own theme, including header.php, footer.php, page.php
header.php and footer.php is working just fine, loading scripts and showing properly, but now i need to add all the other content.
my page.php is currently:
<?php /* Template Name: CustomPageT1 */ ?>
<?php get_header(); ?>
<?php the_content(); ?>
<?php get_footer(); ?>
I would need to somehow add html content to pages, i have about 20 ready made .php pages which needs to be transfered to WP.
Soooo how do i go about making new page (pages -> add new) and using page template while getting the html content to show up?
I've tried to just make new page and in text mode add up all the html into page, but it only shows empty page with header and footer, so the problem is most likely the page.php and i have no idea how to get it to work.
You can do look like this:
<?php /* Template Name: CustomPageT1 */ ?>
<?php get_header(); ?>
<?php
while ( have_posts() ) : the_post();
the_content();
endwhile;
?>
<?php get_footer(); ?>
You are on the good way. While developing a custom theme from scratch is a great challenge it's not too hard.
I could recommend to take it easy and follow this tutorial I found really helpful some time ago, I learned a lot there:
Developing a WordPress Theme from Scratch
You must have the official source documentation always in your mind:
Theme Development
Do some reading and you will see that making themes is really fun and gratifying :)
EDIT:
I would recommend picking a good starter theme or framework and work using child themes. You have plenty of them to pick.
To get started adding a new page to your WordPress site, find the Pages menu in the WordPress Dashboard Navigation menu. Click Add new.
The WordPress page editor looks nearly identical to the post editor, except for a few different boxes located on the right side of the screen.
Add the title of the page, like About. Note: If you have pretty permalinks set up, the title of your page will also be the URL slug.
Next, add some content.
The Publish section of the page editor is exactly the same as for writing posts. When you’re ready to publish, you can either publish immediately, save this or a draft, or schedule the page to be published later.
The Page Attributes section applies a parent page and template to your new page. For the Parent section, you can arrange your pages into hierarchies. For example, you could create this new page with additional pages under it. There are no limits to how many levels you can nest pages.
Some WordPress themes have custom page templates, so the next Template section allows you to apply a template to your new page.
The Order box allows you to order your page numerically. Pages are usually ordered alphabetically, but you can choose your own order by entering a number in this field.
Preview the page one last time, then click Publish. You’ve added a new page to your WordPress site.
This is how your
your index.php should look like :
<?php
get_header();?>
<div class="YourContainer">
<div class="Whatever">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="ContentSectionDiv">
<?php the_content();?>
</div>
<?php endwhile; ?>
<?php else: ?>
<?php endif; ?>
</div>
</div>
<?php get_footer();?>
you can make also a custom loop
<?php
$arg = array("post_type" => "services",
"posts_per_page" => 9,
"order_by" => "date",
"order" => "ASC",
);
$services = new WP_Query($arg);
if ($services->have_posts()):;
while ($services->have_posts()):$services->the_post();
the_content();
endwhile;
endif;
?>

Convert html to wordpress & provide link to menu inside panel

I have an HTML template which I am trying to convert into PHP for WordPress.
The homepage has been converted and is shown properly. Next, the menu in navbar is about, the page that needs to be converted in PHP.
I have just added get_header() at the top and get_footer() below. In between these two I have added the HTML content for my entire page.
Then I tried to provide the link for the menu that I created, but the content of about page is not visible.
Do I need to add any other line for that page apart from get_header and get_footer? Or is something wrong with the link?
Clearly I can't understand what your are trying to say. I think you want to create a page that will show your about menu content.
So in your theme directory create a page name page.php and use get_header(); in first and below get_footer and where you want to show page content write the_content();. like this
<?php
get_header(); ?>
<div><?php the_content(); ?></div>
<?php get_footer(); ?>
after that follow the url of # Sajid Anwar. because for dynamic data you have to create pages(home,about etc) from wordpress dashboard and in menu section add these pages as navigation menu to menu.

If category/page in wp_nav_menu exist

I need your help
I have three custom menu(wp_nav_menu) which I customize via admin menu section.
<!-- first menu ->
<?php companyMenu(); ?>
<!-- second menu ->
<?php servicesMenu(); ?>
<!-- third menu ->
<?php partnersMenu(); ?>
I want to show only one nav menu to which opened post/page/category belongs
For example: when I'm on home page click "Contacts" in menu it redirects me to "Contacts" page and because this page defined (with other menu links) in companyMenu() wp_nav_menu function it shows
It would really depend on how many pages you would need to check against for my solution to be viable- the fewer pages the better.
You could wrap your menu code in if statements and use the is_page wordpress function to check if you are on that page. See the link below for more information.
http://codex.wordpress.org/Function_Reference/is_page
Code Example
if(is_page( 'Contact' )){
servicesMenu();
}
As a general rule the wordpress codex has a great wealth of knowledge which I found really helpful when starting wordpress development

two separate blogs on one wordpress site

I did find one topic that sort of touched base on this but if there is a better link please advise.
I have a self hosted Wordpress website set up typically for a static home page and a separate page that shows recent posts called "Reviews". I need to write posts under a category "Recent News" that would be excluded from the recent post and shown on their own page, a second blog page.
The Codex tells me to add this to the index.php to exclude the category "recent-news":
<?php
if (is_home()) {
query_posts("cat=-3");
}
?>
with 3 being "recent-news". This does nothing no matter where I place it on the page. It still shows up with the recent posts. I'm guessing I'm in the wrong section for excluding categories in the Codex.
How do I exclude a category from recent posts, add a new page called "Recent News" and have it only show posts from the 'recent-news" category.
or have I climbed down a rabbit hole...
you can do it like this: edit your index.php page or create a custom template and then create a page (say "Front Page" ) and assign this template to it. In this template, copy your index.php code or if you feel confident simply create your template and include this code:
<?php if (have_posts()) : ?>
<?php $my_query=new WP_Query( 'cat=-3'); while
($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; ?>
<div class="post">
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
</div>
<?php endwhile;?>
<?php endif;?>
About your second question, simply go to Appearance --> Menu and there you'll see you can add pages but also categories. Simply select the category "Recent News" as a menu element and voilá, now you'll have a page displaying only posts from that category
I do not recommand messing with index.php
I think you should create a page template that will query posts from "Recent News" category.
Then in wordpress create a page and choose the page template you created.
In order to set it as the home page you will have to set it via wordpress configurations.
Wordpress page template
query posts by category
Set static homepage

Cannot Remove Sidebar from Archive Pages in Wordpress

I have a theme that I am developing using the _s (aka: underscores) theme.
I do not want my archives to include the sidebar.php file.
My archive.php and paged.php files do not have the sidebar.php
included.
I created a home.php file which includes the get_sidebar()
function, and edited my index.php to not include that function.
I'm still seeing my sidebar when I click "Older Posts" on my site which brings me to: MYDOMAIN/?paged=2 -- this is not what I want.
Specific archive pages (such as for months and categories) do not display the sidebar, which is what I want.
I only want the sidebar to appear on the front page of the site.
I checked the body tags on my home page and on the paged "Older Posts" archive pages to determine what template is being rendered.
Home page:
<body class="home blog">
paged "Older Posts" archive page:
<body class="home blog paged paged-2">
This leads me to believe they are both using the home.php template. How can I get those pages to use a different template?
What am I doing wrong?
A friend helped me resolve this issue and I thought I'd share our solution. In order to make sure the sidebar appeared only on the front page of the blog and not appear on the ?paged= pages, we added some conditional statements around the call to the sidebar on home.php:
<?php if ( !is_paged() ) { ?>
<?php get_sidebar(); ?>
<?php } ?>
Additionally, this code could be added to the sidebar to keep it from appearing on other pages such as category pages, single posts, etc. While this wasn't necessary since I had used specific templates for those pages that did not include the sidebar, here it is in case it's useful for others:
<?php if ( is_front_page() ) { ?>
<!-- ALL CODE FOR YOUR SIDEBAR HERE -->
<?php } ?>

Categories