What I'm looking to do is add a separate menu for each wordpress page on my site. I did some research and found that
<?php if (is_page('our-staff')): ?>
<?php wp_nav_menu('menu-side'); ?>
<?php endif; ?>
<?php if (is_page('contact-brian')): ?>
<?php wp_nav_menu('menu-home'); ?>
<?php endif; ?>
Is supposibly supposed to switch the menu from, menu-side while looking at the our-staff page, and it will change again when the page is contact-brian, it will change to the menu-home menu.
The problem is, I cannot get both menus to appear, its either one or the other
when you view our-staff page, i want the menu-side menu to appear, and nothing else.
When you view the contact-brian page, i want only the menu-home to appear –
Related
I've created my own WordPress custom theme for a website that I'm working on. It's my first time building a theme from scratch! I'm having a difficulty 1st: to link several pages to the fron-page, or home page. For example lets say that I want to link "Who we are", page + "Contact us", page, etc.. How can I make WordPress understands that each page is different, and link to it? here is what I did so far:
in page.php I placed this code:
<?php get_header(); ?>
<div class="container">
<?php
if (have_post()) {
while(have_post()) {
the_post();
get_template_part( 'template-parts/content', 'page');
}}
?>
</div>
<?php get_footer(); ?>
I also created a content-page.php where I've placed my HTML code. (I'm building the whole thing with an HTML and CSS code that's just like building a website from scratch).
I also want to know when using a plugin, how can I connect that into the pages that I'm adding. For example, if I'm installing a form such as WpForms for a page like "Contact us" how can I link that?
Please let me know if my questions need more details
If I understand this correctly...
You want to be able to display (link) a couple of pages to your home page?
Ex:
[home page content here]
[Connect page content here] [Blurb page here]
If so, you need to pull in the page content into the home page.
Something like:
<?php
$postid = 0 /*Need to get page id, that's the key */;
//Pull in the page data
$featured_page = get_post($postid);
$thumbnail = get_the_post_thumbnail( $featured_page->ID );
//Only show the excerpt in this case
$content = apply_filters( 'the_content', $featured_page->post_excerpt );
?>
<article id="post-<?php echo $featured_page->ID ?>">
<header class="entry-header">
<h1><?php echo $featured_page->post_title ?></h1>
</header>
<div class="entry-content">
<div class="thumbnail">
<?php echo $thumbnail; ?>
</div>
<div>
<?php echo $content; ?>
</div>
</div>
Important! You'll need to get the page id from somewhere. You can hard-code it in, but that's risky if something changes. You can set up an Customizer option that lets the user select what page to use.
https://codex.wordpress.org/Theme_Customization_API
As for the contact form etc. I'd suggest putting it on a page as a shortcode, then displaying the full page, not the excerpt.
I use this code for a theme I built myself. If you need anymore help, let me know, I can show you where to find it.
I'm building a Wordpress site using html5blank as a parent theme for the first time. I have my main pages set up and working using page-slug.php naming convention and all works fine. A couple of these pages require sub-pages but for some reason I cannot get these to work. Example -
On of my main pages is titled 'Agency' and within the agency page I have a number of images which act as links to a number (7) of sub-pages -
I've set the first image up with the correct link and page parent/child as so -
page-agency.php
<div class="row">
<div class="twelve columns agencyproducts">
<p>WHAT PRODUCT ARE YOU INTERESTED IN?</p>
<a href="http://localhost:8888/agency/2k4k-production/"><figure>
<img src="http://localhost:8888/wp-content/uploads/2017/07/production.png" alt="Production">
<figcaption>2K / 4K PRODUCTION</figcaption>
</figure></a>
I've saved the sub-page file as page-agency-2k4kproduction.php in the theme file like the other pages. When I click on the link I get the page.php file showing with my header and form templates but not the sub-page code. Here's what I have in the page.php -
page.php
<?php get_header(); ?>
<?php get_template_part('form'); ?>
<?php the_content(); ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
In my 2k4kproduction.php file I have this -
page-agency-2k4kproduction.php
<?php get_header(); ?>
<!-- custom code -->
<?php get_template_part('form'); ?>
<?php the_content(); ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Am I missing some steps in the hierarchy process?
I can't figure out why the main pages all work seamlessly but the sub-pages don't. I'v tried other permitations - page-2k4kproduction.php, 2k4kproduction.php, page-8.php and they don't work either.
Do I have to save sub-page files in a different file to the main page file?
Does the page order in in the admin make a difference? FWIW I've placed the sub page as next in line to the last main page (8) rather than start a new number order for sub pages.
Really stumped on this one, I'm sure its something quite obvious but I just can't spot it.
WordPress template hierarchy works perfect with page-$slug.php i don't know what could be the reason may be 2k4kproduction slug issue.
it's better to use page-template instead page-slug workaround because if the slug change it won't show your page. go through this tutorial for custom page template.
template-2k4kproduction.php
<?php /* Template Name: 2k4k Production */ ?>
<?php get_header(); ?>
<!-- custom code -->
<?php get_template_part('form'); ?>
<!-- custom code -->
<?php the_content(); ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
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;
?>
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.
I am building a theme in WordPress and being a little out of practise I am struggling to make The Loop work properly. I have inserted the most basic loop into the theme and it displays the content fine.. but when I click onto another page or the news page etc, it still just displays the home page.
I'm not sure if I'm just being oblivious to some blindingly obvious problem with my code, but I assumed that the loop displayed whichever page you were currently viewing, or do I have to set up a mishmash of if(is_page('home')) then do a certain wp_query etc?
The loop code I have is inserted below, and if theres any information I forgot I will try update this post with it.
<?php query_posts(); ?>
<div class="content">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title() ;?></h2>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p>Sorry, no posts to list</p>
<?php endif; ?>
</div>
Summary: The Loop is only displaying Homepage content on every page.
edit:
Even after disabling my plugin with the first loop in it, the proper Loop isn't working. it is the exact code posted above, and it just won't display the page I am on, or the news on the correct page or anything.... what am i missing
Try removing the query_posts(); line and try again
Apparently... My WordPress install doesn't work with pretty permalinks. As soon as I set it back to default settings, it all worked fine, but if I choose any option other than default, then only the homepage shows up (on any theme).