link to internal page wordpress - php

I'm a newbie to wordpress, I added a new page via dashboard, and I want to make a link to this page from the home page so I would love to know what function does that,
I think it would be something like:
>LINK
Thanks in advance!!

You could use
Link Title
Where PAGE_NAME is the page title you have set in the dashboard.
get_page_by_title() returns an object and we use get_page_by_title( PAGE_NAME )->ID to return the page ID of that page. Note that it is more consistent to rely on the page title (which you set yourself) against page ID (which is set by wordpress).
get_page_link() retrieves the permalink of that page ID you passed as parameter.

You can simply link to the page in the HTML body of the home page. For example:
your page
or
your page
Where ###, put the post ID.
More examples
Edit:
If you are editing a template, and wish to obtain the permalink of the post using its ID, use get_permalink($id)
More information about this function
Edit 2:
Based on your comments, you have to switch the permalink format. In WP Admin, find Permalink Settings, and set them to /%postname%/
Read more about these settings here

Related

Navigating links within custom WordPress plugin

I have created a custom WordPress plugin that will display a list of information and i will have the ability to add or edit this information. This seems easy but somehow i am not able to make it work how i would like it to. I have a list of companys and i am showing this list in a table. For each company, i can change its info.
I want to make it so when i click on settings or profile that the page will change and i will pass in the id of the company as a parameter.
I can add a new php page to the href but then that navigates to a new page and i am no longer in the admin dashboard. How can i navigate the url to another page with id without having to leave the dashboard?
When i created a plugin i created submenu pages and when i navigate to these pages... i am executing code all in the same file but different functions with different html which i feel is the way i want when navigating to Settings or Profile for a company.
You can do this by following the below steps:
If you admin/dashboard page URL is something like this: /wp-admin/admin.php?page=list then you need to add extra parameter for settings & profile page like this way: /wp-admin/admin.php?page=list&action=settings&id={id} or /wp-admin/admin.php?page=list&action=profile&id={id}
After that, you need to check if $_GET['action'] is profile or settings, then you need to render the profile page or settings page content respectively instead of list page content. Otherwise, if the action parameter is not set you can render the list page content.
Let me know if you need further assistance.

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.

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.

How do I show only one specific post with comments and author box on the homepage in Wordpress?

I want to show the full post with comments and author box on the home page just as if the actual link to the post was clicked. I will set the canonical on the actual post to point to the home page for seo purposes.
I've seen some code out there, but so far nothing that matches my exact needs.
I only want to display 1 WordPress post on the homepage with the comments and author box below the post. And I want to be able to specify which post will be the one that gets displayed on the homepage. (which post id#)
To add to this, I also need the rel="author" to be visible in the header section. I'm using WordPress SEO by yoast and have selected to not show rel="author" for pages. And all code out there I've tried that shows a single post on the home page treats it as if it is a page instead of a post, therefore removing the rel="author" from the head area.
Please do not reply with how to set the number of posts in the Reading tab or how to set a static page. I already know that. That won't work for my needs.
In summary, when I go to my home page I will see the article I wrote along with the comments and author box below it and rel="author" in the header.
Your best bet would be to set your homepage as a static page, and build a custom template for that page. In the editor, create a custom field that allows your to select a blog post to feature (look into Advanced Custom Fields plugin for easy custom fields), grab that custom field value, and use that to build either a WP_Query, or just call the various bits of information using the ID of that post. The trickiest part is getting the_content() by ID. Here's how you can do that:
Add this function to the functions.php file:
function get_the_content_by_id($post_id) {
$page_data = get_page($post_id);
if ($page_data) {
return $page_data->post_content;
}else{
return false;
}
}
Call your function in your page template like this:
echo get_the_content_by_id([INSERT YOUR DESIRED POST ID HERE]);
If you make a php file in your Theme directory called front-page.php, that will automatically appear as the template for your static home page.
Now as far as the rel="author" thing, I don't know anything about that, so I unfortunately cannot help with that.
Also, I'm unsure why my code is losing it's formatting here.

Is it possible to make a customised Wordpress, seo friendly, url?

I need to change the customized URl of wordpress, where I pass the id in querystring to get data from my custom table. Now i want to see the title instead of that id.
Ex. My site link id http://xyz.com/?page_id=1&pid=12
Now if i try the wordpress permalink it will convert the wp page only like http://xyz.com/test?pid=12
What can i do to make the URl like http://xyz.com/test/title. Where title is stored in database for pid=12.
Yes this is possible and actually pretty easy. Go to /wp-admin/options-permalink.php and look for the custom option that you want. You must have access to the server to update the .htaccess file. Here is more info.
if you want the name of your page to appear as in:
http://www.xyz.com/about/
instead of something like:
http://www.xyz.com/?page_id=398
login to your back end of wordpress
under the settings menu(on left side) click permalinks
click custom structure and in the text field type in:
/%postname%/

Categories