Relative linking in Wordpress - wordpress

I'm creating a website in WordPress that has child pages for multiple locations.
For example, the main page has a Home, About, and Contact pages + 15 service pages.
And the location pages have the About, Contact, and the 15 service pages duplicated.
I have links in the about page linking to the 15 services. Now If I could have a relative link it would be as easy as duplicating this section.
What I want the link to do is that if you are on
https://example.com/about/ and you click a service
it takes you to https://example.com/service1/
but if you are on https://example.com/location/
the same link structure takes you to https://example.com/location/service1
I don't want to have to create 15 different links + different menu links for every single location when all you need to do is add service1/ to the end of the slug you are on.

In Wordpress you should always use the built-in "menu" functionality: You create a menu once (in the WP backend, on the "Design > Menues" page), give it a name, define a position in your PHP template (for example the header.php file) and assign that position to that menu (in the WP backend again). WP will take care of the correct filepaths, regardless on which page you are, by dynamically creating absolute links when parsing the pages. And you can create as many menues as you want, for example the main navigation, footer nav, sidebar menu or whatever.
Here's a simple example for the code in a php template:
<nav id="main_nav">
<?php
$arguments = array(
'theme-location' => 'main_menu_1',
'container' => 'ul'
);
wp_nav_menu($arguments);
?>
</nav>

Related

WordPress page link goes very wrong

I'm building a theme that would have essentially 2 pages, one would be a workshop, and the other would be an art page.
The main page for the domain has header(), footer() the content file is named front-page.php where I noticed that WordPress disregards the "Reading settings" of "Your homepage displays" ( Your latest posts / A static page )
I've created art-page.php to include new headers and footers for art (header('art'), footer('art'))
I followed the WordPress Codex of creating a new page, so art is a page I've published, seen that it's ID is 1742, I created the home page link to art as: <div id="art-link"></div>
Result:
When pressing on that link, it loads /the-art with a 200 response, including all the css and js for it, yet it loads the home page and under the footer of the home page it creates another home page with the header, then in the content a row with "art" (the name of the page) following by the main footer.
Expected result:
From the home page, click on the art link from above, wordpress will load art page (art-page.php) as a whole new page.
art-page.php
get_header('art');
?>
</div>
<h1>test art</h1>
<?php
get_footer('art');
?>
I'm a programmer with a basic grasp of the wordpress, yet struggling to create the expected result above.
Thanks,
Bud
I now study how to make a theme in wordpress.
First you need an Index.php file and a style.css file (these two files are the minimun)
You can cut the upper part of index.php and create the header.php an the down portion and create the footer.php.
You can have a static page as 1st page and the filename can be front-page.php and another page for blog.
BUT if you want to see a set of archives you use archive.php (post in same category, or of the same author e.t.c)
IF you want to see a post (one) you use the single.php or page.php for a single page.
In wordpres we have pages (static content like About us) and post this can written new info from author.
If you have difficulty, read a givem default theme, or use a starter theme and convert it to what you want.
Some starter themes to use are:
https://underscores.me/ (from authors of wp)
http://jointswp.com/ (Freamework foundation)
https://understrap.com/ (Bootstrap 4)
Before to start read about theme hierachy in wordpress
https://developer.wordpress.org/themes/basics/template-hierarchy/
example themes
https://medium.com/pixelperfecthtml/step-by-step-guide-to-convert-html-template-to-wordpress-theme-8d89264eb4be
https://www.elegantthemes.com/blog/tips-tricks/converting-html-sites-to-wordpress-sites

Archive displayed on a custom page to be used in menu structure

I would like to direct users to appropriate archive pages from within the menu. If I want this I need a page that I can attach to the menu.
How would I display the exact same stuff as on the archive page (archive.php) on another page so that pagination and functionalities remain the same, but some stuff will be taken from the actual page ? (can create custom page template of course)
I'll still have to show a sidebar for the page that you visited and not archive's sidebar
Breadcrumbs path will still have to show current menu item position and not archive page path
To show sidebar from the actual page is of most importance here.
EDIT
What I want to achieve is this actually:
Lets say I have a page
http://my.page/subpage/something/notifications/
I want that on this page, I can display exactly the same stuff as on the certain archive page which is here:
http://my.page/subpage/notification/
('notification' is a custom post type here)
I already have a solution that displays all archive stuff on another page (created a page template for that), but its a bit complicated to display title, breadcrumbs and sidebar properly for each page, since some of these should stay the same as they would be, but some should take the value of another site.
You can create a custom page template and assign it to a page. On that page you can use get_posts() to query the posts you want, like this:
global $post;
$posts = query_posts( /* Your args here*/ );
foreach($posts as $post) {
setup_postdata($post);
// Do your stuff as in archive.php
}
wp_reset_postdata();

Additional content in Wordpress - possible use of Custom Taxonomies

I'm fairly new to the Custom Taxonomies in Wordpress, but I wanted to see if I can use this feature to achieve a list of items that link of to pages within my site.
Here is the final HTML I am looking to output:
<ul>
<li>Custom Taxonomy 1</li>
<li>Custom Taxonomy 2</li>
<li>Custom Taxonomy 3</li>
<li>Custom Taxonomy 4</li>
</ul>
As you can see above I have various taxonomy items (i.e. 1 & 4) both linking to the same URL.
So I am looking to see if it is possible to:
Setup Custom Taxonomies with two data inputs (name & custom URL) that I could reference in my theme
Alternatively, I would just create another HTML section where I could define the content (& links) in each post. (Almost as if it was a secondary 'content' area).
I would prefer not to use a plugin if possible, as I am attempting to maintain autonomy of the background code. Is this possible?
EDIT:
Sorry if this wasn't clear. I'm not 100% if Custom Taxonomies is the correct way to go.
Basically, I have a list of 'features' that I want to tag on each of my 'portfolio' posts. I want to display these features in a simple (linked) unordered list.
The important thing however is I don't want the list to be linked to a category/archive (like normal tags work). I want to be able to define the URL to an existing 'service' page for each feature, so the user can read more.
Therefore I need to be able to define both the name of the feature and the url of the page the link should point to.
As the list of 'features' & the pages they point to will always remain the same, I thought Custom Taxonomies may be the solution.
You can make a template for each taxonomy term , in your case for each feature.
So ie if you have a term with the name 'premium' you can make a taxonomy-features-premium.php template file and place whatever you want.
So on your page where the portfolio post is being display you can show all the features with their permalinks and if you have make the template files for every term when you click on a term will show the template file for the term that you selected.
or inside the template files you can just redirect them to the page you want.
Update :
In your single-portfolio.php (the template file responsible for showing the portfolio custom post) you can put somewhere in your code (depending your needs and the style of your page) :
echo '<ul>';
echo get_the_term_list( $post->ID, 'features', '<li>', ',</li><li>', '</li>' );
echo '</ul>';
Doc : http://codex.wordpress.org/Function_Reference/get_the_term_list or you can use : http://codex.wordpress.org/Function_Reference/get_the_terms if you want to take more control of your terms.
This would return something like :
<ul>
<li>Premium Feature</li>
<li>Basic Feature</li>
</ul>
So now you have all the terms belonging to the specific post. So if you create a taxonomy-features-premium.php template file, when the user clicks the Premium Feature link wordpress will show whatever is in that template. Notice that if you don't have a taxonomy-features-premium.php template wordpress will search for a taxonomy-features.php (that template is usufull if you want all your terms to be shown the same way). More about template hierarchy here : http://codex.wordpress.org/Template_Hierarchy#Custom_Taxonomies_display
Now inside the template or you can copy paste the code that you have in your page + add some modifications corresponding to the term or you can just redirect to the page you want : wp_redirect(get_permalink( $your_page_id )); exit;

wordpress. error creating content for custom templates with twentytwelve theme

i'm using the twentytwelve theme and i have to write custom content into my example template.
I want to maintain my header content so the main structure is the following
header = id page, wrapper
ex.page = primary, content
footer = close wrapper, close id page
If i have understood correctly, if i want to insert content into the middle of my page i have to do it into my template page (that is a copy of the main page.php), that is in the middle between my header and my footer
For example i want to insert a div into which insert the loop of such category.
The problem is that it displays me nothing, like i've wrote nothing. I can only see the contents if i erase all the originary div, but it's not what i want to do, just because the only div is the page which is my container.
I can't catch what i have to do.
Can you tell me what i forgot to do?
Thanks,
Alex
page.php is a "master" document. header.php, footer.php and (if it exists) sidebar.php are all imported into page.php. Twenty Twelve also uses atomized content templates. You may need to add your div to content-page.php, which is also imported into page.php. content-page.php is used inside the wordpress loop, and encapsulates the code that pulls in the actual article elements from the wordpress database.
If you are trying to add straight HTML to the templates, ensure that you are not adding code between the php brackets:
<?php // don't add html here ?>
<div>do add html here</div>
Depending upon the type of wordpress page you are trying to display, you may need to consult the Wordpress Template hierarchy to determine the proper Wordpress naming convention for your template file (the copy of page.php).
Technically speaking, everything in content-page.php can be put into page.php replacing the get_template_part function. All the 'content' pages are totally not required and can be combined into one file if you want simplicity.
In my opinion, it's easier to start from scratch when learning Wordpress rather than try and re-work something. The default wordpress themes don't lend themselves to be beginner friendly.

Load Wordpress widget in a fixed div

I'm working on a site that sells various products. Currently we're presenting those products as fixed width (no sidebar) pages within Wordpress. I'm using "Simple WP Shopping Cart" to drive the transactions (because all of the other solutions are bloated and break stuff). With this plugin you get a widget that contains the cart...
What I want to do is load that cart to a fixed div that sits on the side of the page, rather like all those "feedback" and "socialise" bars you see on a variety of sites these days. I've done the div, so that's not a problem, but I can't seem to get the widget to load.
So basically: how would one go about loading widgets, or a widget, in a div that isn't the "designated" sidebar in Wordpress?
you need to "designate" it as a sidebar... :-)
A "sidebar" is actually a placeholder for widgets .
<div id="mysidebar">
<?php dynamic_sidebar( 'Right Sidebar' ); ?>
</div>
from the codex :
You can load a specific sidebar by either their name (if given a string) or ID (if given an integer). For example,
dynamic_sidebar('my_name')
will make a sidebar (widget placeholder) for a registered sidebar with :
register_sidebar(array('name'=>'my_name',)).
read here for more : http://codex.wordpress.org/Function_Reference/dynamic_sidebar

Resources