Bilingual Wordpress Website [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
I am developing a wordpress website and I would like to have two instances of the website, one in english and the other in german. My goal is to when a user visits my website, the user is redirected to the correct language, based on his/her browser language. But I want to do this with only one instalation of wordpress. I can make duplicates of the pages (one in english and other in german), make a homepage duplicate by setting the homepage as a template for pages. My issue is the menu. How do I set different menus to different pages?

You'll need to register a new navigation menu, and add it to the templates you are using for the German pages, then make a new header template, then set your templates to use that new header. Here's the steps needed to do this:
Register the menu
In your theme's functions.php, you'll need to add some code like this at the end of the file:
function register_german_menu() {
register_nav_menu('german_menu',__( 'German Menu' ));
}
add_action( 'init', 'register_german_menu' );
What this does is tells Wordpress that you want to add a new location for a menu to be customised in the Appearance > Menus page. You should from now be able to add items to your menu, but they won't show up anywhere yet.
Create some page templates
You will have to create a set of page templates for the German half of the site. You will need a new page.php and a new header.php template. I would recommend calling these page-german.php and header-german.php respectively. For your page-german.php, copy paste the page.php template into page-german.php, and add this comment at the top of page-german.php:
<?php /* Template Name: German Page Template */ ?>
This tells WordPress to recognise it as a page template, and tells it it's name. This makes the template selectable on each individual page.
Now, you need to make a header template. Copy paste the header.php template into the header-german.php. In this new template, look for a line that looks something like
wp_nav_menu(array('theme_location'=>'something'))
And change it to:
wp_nav_menu(array('theme_location'=>'german_menu'))
This will display the German menu instead of the regular menu.
Now, go back to page-german.php and look for the line that looks like:
<?php get_header(); ?>
And change it to:
<?php get_header('german'); ?>
This tells Wordpress that on this page, you want to use the header-german.php file to generate the header rather than header.php.
Setting up page templates and Menus
First, go to the Appearance > Menus tab, and create a new menu, then assign that new menu to the slot "German Menu". Then, you will need to go through all the German pages of your site, and in the right sidebar when editing, set the page template to "German Page Template". Now your pages using the new template will display the German menu instead of the English one!
Further?
If you have other templates that need converting, then you can convert them as described above, by making a copy and changing the get_header() call. I didn't really expect this answer to be this long but I hope it helps!

You can use a plugin like WPML to achieve this but if you dont want to use a plugin, you can edit header.php and add a condition on which menu to load depending on the browser language.
e.g.
<?php
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
switch ($lang){
case "en":
//display english menu
break;
case "de":
//display german menu
break;
default:
//default to english or german menu
break;
}
?>
Above code was taken from: Detect Browser Language in PHP

Related

Wordpress - how to add general content area to a specific “page” that's not actually a page?

I purchased a WP theme https://themeforest.net/item/pressville-municipal-wordpress-theme/19949423 and need to add general content area to the People page: https://preview.themeforest.net/item/pressville-municipal-wordpress-theme/full_screen_preview/19949423?_ga=2.67243158.624148492.1570058772-1881232054.1569979687
The People page is actually a section in the WP dashboard (kind of like Media or Portfolio section) so technically not a editable page in the WP backend. I contacted the theme creator and was told that it's customization (not included w/theme) and advised to hard code text into the php. The problem with that is it's not accessible to other users who have no design or code background.. Is there a way to create a page with editable content block for this People section so it's easily editable without knowing code?
Also, the “People” header text changes if you click on subcategories (to “Elected Officials”) for example. When you click a subcategory, the main menu (People page) no longer shows as active which can be confusing to users. Is there a way to fix this so header stays consistent (like Contact page header) and menu item shows active regardless of what subcategory(All, Elected Officials, etc) is selected on the People page? Thanks.
You can create a regular page called "People's page" and add text to it. Then if you want to show that page's content into a PHP template you can do the following:
Step 1. Create the Function
Open up your theme’s functions.php file and paste the following code, likely at the bottom of the page.
function cn_include_content($pid) {
$thepageinquestion = get_post($pid);
$content = $thepageinquestion->post_content;
$content = apply_filters('the_content', $content);
echo $content;
}
Step 2. Use the Function in a Template File
Next, open up the specific template file you want to include the Page’s content on and paste in the function:
<?php cn_include_content(31); ?>
Replace 31 with the ID of the Page you want to include. How to find a page ID.
Is sounds like you need to go to your wp-admin and click appearance/ menus. Here you can remove these menu items that might be default but have no pages associated with them. You can then add the pages you want and come back and create a custom menu. Hope that answers the first part of your question.

I think I have misunderstood the idea behind front-page.php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm entirely new to WordPress but have been tasked with creating a website for my uncles business. I'm trying to understand a bit more about the mechanics of WordPress before I do any more coding so I have a question about index.php / front-page.php.
I had been working on index.php before I even decided to implement WordPress so everything is hard coded. So at the moment I have a fully populated index.php file that I custom designed myself. My understanding of WordPress so far is that everything is dynamic. So I feel like what I should have done is created a front-page.php with a function within it to call the static 'Front page' that I create within the WordPress GUI, then outputting it using the_content();?
Is it okay to have hard-coded in WP, or is this against best practice? Obviously with my current implementation we will not be able to edit the file. How would I go about editing the CSS for this - For example I have a div named 'services' with a background image for this div in the CSS. How would this be implemented from within WP?
Ok i think you got it wrong, wordpress works on themes. In order to make your html design work with wordpress you will first have to create theme. Creating a basic theme is as simple as creating a new folder. Here are some of the basic files that are important, and difference between index.php and front-page.php.
style.css, This file will contain some comments that will define
the details about your theme
Header.php, The header part of your html design goes in this file including the main menu and slider.
Footer.php, the footer part i.e. copyright statements, footer menu etc goes in here
index.php, this file is used by default for list of blogs, but you can change it from settings > reading > and then choose the page you want to show as home page.
front-page.php, this is similar to what index.php does but it has more priority. So if both the files are present then this will be used. Another advantage of front-page.php is that you can add any kind of hardcoded html in here as it is not used by any other page.
page.php, this file is used to show all content of wordpress pages, like about, contact etc.
single.php, this file is responsible for showing a single blog post.

Is it possible to figure out the code used to build a Wordpress page from a permalink (slug)? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Given a Wordpress permalink (or slug), is there a way to track backwards to figure out the code that generates the displayed page? For example, using this URL "my.domain.com/product-category/lamps/" or "my.domain.com/product-category/tables/" can you track the code used to make up the page that is displayed in the browser?
Basically, here is my problem. I've been hired to complete/fix a Wordpress site that was heavily, heavily modified by the original programmer (who quit and is not available to help). The site uses the Stylo Theme with WooCommerce. The code to build the product catalog pages has been modified and I'm having a hard time finding all the PHP functions that do these modifications. There are no pages in the control panel that have a permalink that corresponds to the URL (shown above); so I don't even know what template he has used to start these pages. He did not write a widget or plugin to make these changes, but changed the original code. His modifications broke (or deliberately disabled) some of the search functionality (min and max price range) built into the theme.
So, back to my question - given the final permalink displayed in the browser's address bar, can I backtrack the code 'path' used to build the page?
This is an easy way to get the path of the template file that is used to render the current request. Place the code in functions.php in your theme or in a plugin and this will print the path on top of your site.
add_filter ( 'template_include', 'debug_template_dump' );
function debug_template_dump( $template_path ) {
echo $template_path;
return $template_path;
}
In my experience in similar circumstances, the easiest way to proceed is this:
1. Log in to the site. Make sure you have the wordpress admin bar enabled.
2. View the page in question from the front end.
3. Select 'edit post' or 'edit page' or whatever is offered
The link you supplied is likely to be for a woocommerce product category. Customization was probably performed either using templates (look for a woocommerce folder in your theme) or by utilizing hooks to add custom functions (look in functions.php).

How to create a custom page in Wordpress? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
How can I to create a custom page in Wordpress 3.0. Give me any link of tutorial.
WordPress provides a clever way to do this called Custom Page Templates. To create a WordPress Page Template, you’ll need to use your text editor. Go to the directory on your server where you installed WordPress, and then navigate to the directory of your theme. Usually that looks something like this: “/wp-content/themes/default” where “default” is your theme name.
That’s where you will create your custom page template file. Create a file called “cover_page.php” and add the following code to it:
<?php
/*
Template Name: Cover Page
*/
?>
<?php get_header(); ?>
Here's my cover page!
<?php get_footer(); ?>
more details read this
http://www.expand2web.com/blog/custom-page-template-wordpress/
To add to the answers above, one good way is to open a text editor (I like notepad++) and copy and paste the content of the page.php file into a new file, including the php template name code in one of the previous examples.
Call it something unique (like custom_page1.php ) and upload this file via ftp to your active theme folder inside your wordpress install on your server. You can use filezilla for this or another FTP program.
Refresh your editor page in wordpress and you should see your template listed with the others on the right.
Now when you publish a page you can choose this template from the dropdown menu on the side panel.
You can use the Page Template feature of wordpress to create a custom page.
First create page using pages->add new.Then,give title (for e.g. aboutus). Then click
Publish on right side of the window(no content is needed for the custom page).
Then,on left side of window click Appearance->Menus.
In menus window,on left side you will see Pages heading,in that click Most Recent and
check aboutus page. Then it will be shown on right side window.
Then,on left above Pages heading, you will see Custom Links, in that enter # in URL textbox
and aboutus in Label textbox. Then click Add to Menu button.
Done. You will see the menu as custom on right side of the window and then click save menu
button at the bottom right.
Then to check, on left top of the window click the website or your blog name. You will see
the menu. Click on it. No changes will occur.
That's it, done!
Here are some plugins you can use while creating what you need then you can turn them off or remove them.
http://wordpress.org/extend/plugins/theme-file-duplicator/
http://wordpress.org/extend/plugins/theme-file-maker/
Very easy way to do what you need.
This is a very simple part of WordPress theme development, I suggest giving the documentation (the WordPress Codex) a good read before going any further. There are also a tonne of great WordPress tutorial sites out there that will get you heading in the right direction.

Using WordPress as a CMS

I am currently teaching myself WordPress and working on my own CMS site.
My site will consist of approximately five pages where the header/sidebar menu/footer will be seen on all these five pages.
Beginner here and questions are as follows:
All these five pages will consist of different content, for example, every page will have a image banner representing the menu option just clicked, for example, "About Us" on page 5, "Promotions" on page 4 etc and then some text beneath that and then possibly some images inside a carousel set up.
Within WordPress, how would I tackle this, i.e. do I just create a page in WordPress, position the banner image at the top of the page, then have a few breaks and then insert the carousel of images - is this correct?
If not, do I need to create a separate php file called aboutUs.php that has this markup and then somehow link it to a WordPress page?
On my landing page of my site ONLY (page 1), just above the footer, I want to display a div section that displays all the sponsors of the website along with a URL to click to their websites - how would I go about doing this in WordPress?
Furthermore, with my menu, how do I link my menus to point to the WordPress pages relating to that menu option?
If you use the 'default' template that comes with WordPress you could do something like this to generate different content on different pages without creating separate php files (this would go in page.php):
<?php if(is_page('About Us')) { ?>
<?php $about_query = new WP_Query('category_name=aboutus-&showposts=1');
while ($about_query->have_posts()) : $about_query->the_post(); ?>
<?php the_content();?>
<?php endwhile;?>
Essentially, in this you could just create a post and an 'aboutus' category to reference it. The page of 'About Us' (referenced through is_page()) would contain the content you wanted to display.
First, some background. Wordpress has a number of ways to display stuff, such as images, text, and query results; here's a list:
THEMES
You can modify your theme files directly to do whatever you like. This will probably involve learning a lot about PHP and the Wordpress internals, but there are plenty of books, and the Wordpress Codex to help you. You can get themes from the Wordpress theme directory.
PLUGINS
There are huge numbers of Wordpress plugins, any one of which might fit your need. Plugins will require configuration, but generally won't involve learning PHP -- just how to install and configure them. Most of the SEO (Search Engine Optimization) plugins will allow you to place custom HTML in the templates (nominally for ad placement, but you can do anything you want with it). You can get plugins from the Wordpress plugin directory.
WIDGETS
The base Wordpress software and many plugins provide Widgets. A widget is a display element that can be docked in one or more widget areas. Typically a widget will be a chunk of HTML (often an unordered list) that has the theme's style sheet applied. Widgets are often used for ad placement, navigation elements (menus, dropdowns, breadcrumbs) or to provide tag clouds, category lists, calendars, etc.
SHORTCODE
A shortcode is a macro that can be placed in a page or post, that will return a chunk of HTML. Shortcodes can take parameters that will affect what the shortcode returns. The base Wordpress software provides some shortcodes, but many plugins will provide shortcodes as a way to get more functionality without the need for widgets or theme modifications.
With all of that in mind, here's my answer(s) to your question(s):
Modify your theme to include a page template, and add your image selection code to the template. Then create your individual pages, and then select your template while editing the page.
The 'landing page' can be any page (instead of the default blog index page); create a 'home' page and a 'home' page template that includes your advertisements. Alternately, use a SEO plugin to add the ads above the footer.
I don't know what theme or plugins you use, but generally you can configure a navigation menu to work from a list of pages, specifying either which pages to include or which pages to exclude. If your theme doesn't include this functionality, I'd recommend choosing a different theme.
Look into Wordpress "page templates". The Wordpress codex can help you understand this.
If you edit a post in WP you will notice the option to use a template. That is your goal. Learn how to work with them.
Wordpress themes are composed of multiple files. One of them is the header.php file which contains the header content. The footer.php file contains the footer and the sidebar.php contains the sidebar. These are the usual conventions. They're not strict. There will be a couple of main files which include these (e.g., index.php - Used for articles, page.php - Used to display pages etc.)
If I were making a setup like yours, I'd make five "pages" (using the backend) and then customise my page.php file to present it properly. I'd still keep the header, footer and sidebar separate from the page.php file since they'd be there for pages like 404s etc. as well.
Just put something in the content of the landing page to display this.
IF you're doing theme development, the right place to look at is http://codex.wordpress.org/Theme_Development

Categories