create a function in header.php - php

i created a wordpress website theme and i want to create a function in the header.php that function should create a menu of one link that can be changed by using any way like for example widget
this is the link :
<li>arabic</li>
and i want the function to let me change the url to go to page
like when i am in "contact-en" page the url of the link should be "contact-ar"
and when i am i page "contact-ar" the link should be "contact-en"

Why don't you use Menu for WordPress?
To use this, go to "Appearance" -> "Menus".
Make a menu with any name. Select the menu from "Main Menu" and save it.
Put your link under "Custom Links" and the text you want to show under "Label" and click on Add to menu. Repeat this process until all are put. Then save it and the menu will appear now in your header menu.
Ask me if you have any further questions regarding this topic.

Related

Reference Base URL in Wordpress

I am working with a plugin that autogenerates a page in Wordpress.
The "Event" plugin creates a new page with slug "events". The page is not registered in the "list of pages".
I need to add the events page to the main menu.
My problem is when I go to the appearances->menu, there is no element in the list of pages to add to the menu. The only way to add the item is to manually create the link in the "custom link".
If I'm going to do this, is there any way to parameterize the baseurl? for example: instead of using link "HTTP://homepage.com/events", I'm looking for "{{ base URL }}/events"
Is this possible? if so, how?
Thank you

WordPress: Adding home page (=latest posts page) to navigation properly

I have a WordPress template displaying the latest posts on the home page (www.mydomain.bla) as it is the default setting in WordPress:
Now, I want to add a link referring to my home page in my navigation (with Appearance -> Menus). The only way I found to do this is by adding a custom link referring to my domain.
Here's my problem:
Even though the link itself does the job, one thing is not working. When navigating to a single post (like www.mydomain.bla/a-single-post) the needed classes indicating the parent link (current-post-ancestor current-menu-parent current-post-parent) do not appear to a custom link like they would to if I had a "Post page" which is not the Homepage.
Is there a way to add a link referring to my posts-showing homepage properly?
Thanks a lot for your help!
Create a new template named "Our blog" and paste the code for posts in this template. Now add a new page named "HOME", select OUR BLOG template and publish the page. Now go to the reading section under the setting tab and change the setting from your latest posts to a single page and select your HOME page.
Now you can add page rather than adding a custom link in the menu.

WordPress : Cant change link for navigation item

I'm customizing a WordPress theme so problem is that I've to change a link. its in Arabic for example instead of this i want to make it like this but problem is that i don't find link for the item see attached image
now how do i change its link please help.for some of the other links i can change but not this one
You can't change it because it is a page. You can remove it if you don't want it in the menu, and add another page instead or you can add a custom link, for which you can specify the Navigation label and the url.

Dynamic link to page in Wordpress

So I'm attempting to create a dynamic WordPress link that displays within a post which would change according to the subject page that displays that post.
The link is displayed in a Bootstrap breadcrumb list. I'm using the WordPress "Content View" plugin to gather all posts of a given category ex. "Public Space", and display them on a specific "Public Space" page I've created within WordPress.
The dynamic link currently in use displays the proper title of the category of post being viewed, "Public Space", but it links back to the specific category page instead of my "Public Space" page that uses the proper formatting I need through the "Content View" plugin.
Is there any way to accomplish this without creating individual .php page files for each subject?
Any help would be greatly appreciated!
Here's my code for the breadcrumb:
<?php the_category('title_li='); ?>
Link to the website post with the dynamic breadcrumbs:
http://parkerrichard.com/wordpress/public-space/judgement/
Link to the page the "Public Space" breadcrumb should dynamically link to (and change depending on the post category):
http://parkerrichard.com/wordpress/public-space
Thanks,
Parker
Sorry, I didn't read your post fully. Your problem is you're using a plugin to do templating work, when you could edit the "category.php" page to look like you want.
But if you have to use the plugin, then try this:
Go to Settings > Permalinks in your admin menu.
Then set your permalink structure to custom, and put this in the box:
%category%/%postname%
Then underneath that in your category permalink name field, put a single period - .
Now your category permalinks will have: http://yoursite.com/wordpress/category-name/ instead of yoursite.com/wordpress/category/category-name/
They should link up to the right place now.

WordPress how to add another page?

I am using the newest version of WordPress (version 2.8.4)
I'm wondering how I would add an additional page.
I have a navigation that looks something like this.
home | about us | contact us | ... etc.
I read somewhere to go to pages -> add new but it forces me to put the content within WordPress rather than edit a PHP file itself.
How would I be able to enter PHP in it? Is there something else I can do?
For example if you want to add home, "About us" pages:
You have to create template pages for this.
For this you need 3 files: header.php, index.php and footer.php.
If you are using an existing theme, you will find these three files in your theme folder itself.
For creating your home page, copy the following into your index.php file:
<?php get_header(); ?>
<body>
/* include whatever u want in ur body tag */
<?php get_footer(); ?>
index.php will be automatically assigned to home page.
For the "about us" page, create a file named aboutus.php (whatever name you want with .php
extension) and copy and paste this code.
<?php
/**
* Template Name: aboutus //don't forget to add this name according to ur page name
*
* Selectable from a dropdown menu on the edit page screen.
*/
?>
<?php get_header(); ?>
<body>
/* whatever u want in ur body tag */
<?php get_footer(); ?>
Then go to dashboard of your website or blog, there click pages->Add new,
give the Title as Home. Then click publish button on right side of the (Add new page) window.
Then, on left side of the screen, again click pages->add new, then enter title as "about us"
and then, in right side of this window, you will see a dropdown box named template, click the dropdown and select "about us" from it. Then click publish button.
Now we are going to create menus to appear in the website or blog. For this,
On left side of window,click Appearence->Menus.
On left side down of window you will see Pages heading, in that click Most
Recent, check home, aboutus pages and click Add to Menu button.
Then, the selected pages are displayed on right side and click Save Menu button on right corner.
Then, on left top corner, click your website or blog name to view your website with the two menus with their pages.
Create a Template in your theme folder, then set the page to use that.
If you want to do it without creating a Template, you may be able to use a plugin such as Exec-PHP, however this brings with it a bunch of possible security issues.
Why do you want a content page outside of Wordpress and outside of the WP loop? You still need to use a template and WP includes or you'll run into permalink problems.
You can make a WP page but exclude it from navigation, if that's what you're after, with something like Exclude Pages.
I'm a bit confused about what you're asking, but if what you're looking for is a way to have a link in your WordPress navigation that goes to a page you create outside of WordPress, you can use this plugin:
http://wordpress.org/extend/plugins/page-links-to/
If this and the other answers aren't any help, you might want to edit your question to clarify what you're trying to do with the php.
Good luck!

Categories