Wordpress sidebar to load specific posts - php

I am building a website in Wordpress and I need a sidebar that when you click the name of each post on the sidebar, it loads that specific post in the middle of the page.
I am unsure of how to go about doing this.
I am new to wordpress and php and any help is appreciated :)

Well basically as far as I understood you want to replace the current middle content with post content.
To do that you will have to use AJAX connection. You will need to pass post id to function, where you will retrieve post data and return it back to the page, where you will need to just insert it in the content.
I suggest that you check these links -
http://api.jquery.com/jQuery.ajax/
http://codex.wordpress.org/AJAX
Example -
http://net.tutsplus.com/tutorials/javascript-ajax/uploading-files-with-ajax/
http://www.1stwebdesigner.com/css/implement-ajax-wordpress-themes/
A more simple solution would be just to add the_permalink(); to page link, so it directly links to the post.

Related

Change URL of previous posts and next posts link in Wordpress

I'd like to change the URL of the <?php previous_posts_link ?> and <?php next_posts_link ?> that are being outputted by Wordpress.
Problem:
When I am on my single page, I am getting this kind of an url:
http://example.com/post-title/2/
What I like to achieve:
When I am on my single page, I would like to get:
http://example.com/2/
So, the URL without the post title!
I don't know if this is even possible, but I'd like to understand if this is doable or not.
Could someone help me out here, please?
Get next/previous post object using get_previous_post() & get_next_post() and build your custom url.
You can create custom URLs for your pages within the .htaccess file. I found a useful link that might be able to help you out from another thread. php custom link and custom pages

Multiple pages for custom_post_type posts

I have a custom_post_type that creates the posts for campaign_posts, they are displayed singularly on the front-end of my site with the page template single-campaign_posts.php.
Now, what I am trying to achieve is;
single-campaign_posts.php displays the post (already taken care of)
A second page that will display a frontend editor of the post (contents of this page is already taken care of
A third page that will display analytics for the post (again, the contents of this page has been taken care if)
So when a post is viewed they can click a link within single-campaign_posts.php to display either the analytics page or edit page. The pages that are linked to must be;
able to recognize that the contents of that page relate to the post
the URL slug is for example if the post was /campaigns/dummy-post would be /campaigns/dummy-post/analytics for the analytics page and /campaigns/dummy-post/edit-campaign for the edit page.
I have tried using nav tabs to do this and it works, however, I would rather have the contents on separate pages.
I hope this enough information to obtain my goals in this. I cannot see much point in adding details of the functions.phpor single-campaign_posts.php but if they are required then please let me know.
I hate seeing posts like this, but I have come up empty on searches for a solution. In its very basic form, I need three pages that all relate to the single post.
Thank you for your time and if you need more information please let me know.
I have found the solution to this now.
The solution was to use Rewrite API/add rewrite endpoint as seen Rewrite API/add rewrite endpoint
An example is posted in this question - Create Post tabs in single-{content-type}.php with Custom Field values

How to add <a href> to link other post in Wordpress

I am new to wordpress, I have searched this thing on net but unable to find exact solution.
I have created a post that contains the Actor's Profile and the list of Movies Actor has worked in. Each Movie has also a different Wordpress Post that contains Movie details.
Now i want to create a link on each Movie, by which user can view the details of that particular movie.
This following link gives the result
<a href="http://localhost/wordpress/2015/10/09/movie-main-page">
but if i add this in each post, then it would be very difficult for me in future, when i will be uploading the site on web server, to change each link individually on every post.
I believe that there must be some way out there better than what i doing here, but somehow i am unable to find that trick.
Kindly guide me.
Thanks
You can use the get_site_url() template tag to return the site url and concatenate into the string. I haven't tested this code, so it might need some tinkering, but it should get you started:
<?php echo '<a href="' . get_site_url() . '/2015/10/09/movie-main-page">' ?>
wordpress link to anchor on another page
If Your Movie Page URL is Same Then You can use
echo get_permalink('11');
Here 11 is id of the page/post.
or if you have different different post for movies that can have different urls.
You can use wp_query loop for each post
[https://codex.wordpress.org/Class_Reference/WP_Query][1]
and use simply **echo get_permalink();**
There are two ways to achieve what you're doing.
The first and easiest way would be to run a search and replace on the database to change any URL's in your posts to the new URL. You should have a look at https://interconnectit.com/products/search-and-replace-for-wordpress-databases/ .
You could also use Advanced Custom Fields to Achieve this. You would need to use the post object field to link to another page within wordpress. With the post object field you can create a field for each post that links to another post which you can then display in your template. Take a look here https://www.advancedcustomfields.com/resources/post-object/. With this method you could transfer all the content and associated links would still work.

Display a single blog post

I am using PHP + MySql.
My goal is to be able to click on a blog post title and have the site link to a page that will display just that blog post (pretty much like any wordpress blog).
I have searched for the way to do this over and over and cannot find any information that shows me how to and I don't even know where to start. IF someone could just point me in the right direction or to an article that will show me how to do this.
I am assuming that i need to us Jquery to create a variable that takes the ID but I really have no clue where to start.
Just wrap the title in an anchor tag with the URL of the post as the value for the href attribute
<h1>Title goes here</h1>

Adding a hyperlink to every comment

Here is an image of my comment format: http://oi40.tinypic.com/8w07jt.jpg
The hyperlink to each individual comment is the date and time with the url in the format of, for example: /nottingham/#comment-184
After going through my comment templates I found that these two functions do the following,
get_comments_link : Retrieves the link to the current post comments
AND
comments_link: Displays the link to the current post comments
The problem is I have no idea where to include these functions so it creates a hyperlink to every comment within every comment. Once this link has been created I'd also like to assign a div to it so I can format it to be in the bottom right corner of each comment.
My final goal is to manipulate the link so rather than the comment link itself it will automatically work in the facebook.com/sharer.php which I feel I can do myself once I figure out the previous part. Essentially it will be a share on facebook button, but I have found no plugins which do this yet and thought describing it as a hyperlink would be an easier way to explain what I'm trying to do.
Elsewhere I've been told the following: but not sure how to implement this...
In functions.php I'd add a 'get_comments_link' filter to return the desired link, including the tag you need. Note that this is a filter, not a function. There is function with the same name, but it's part of WordPress itself. Use the filter to add a div to the existing link. Then style the new div to position it where you want it. I notice that the Photoria theme repositions the Reply link, which is coded at the bottom but displayed at the top. In the same way, your new will be coded at the top but displayed at the bottom. Also see add_filter in the Codex. Add the new div to $link before returning it. The new div will need a class attribute so that you can work with it in CSS to make it look the way you want.
I hope I've made the question clear, please ask if I haven't. Thanks in advance!
You need to edit your comment template in your Wordpress theme.
Default is located in /comments.php
Some more informations could be found here : http://codex.wordpress.org/Function_Reference/comments_template
Finally answered it myself, the code used to display the comment link was:
<img src=""
Which was inserted in my comments template file within my comments body div which I then put into another div so I could format it itself to where I wanted it positioned.
Currently in the process of making the link automatically share through the facebook sharer...
Hope this helps anyone with the same problem.

Categories