I have a simple page. On this page, I have blocks. The blocks get their unique ids when clicked open (example: http://blog.com/#brands). The ids are variable:
<div class="block wide" id="<?php echo $postid ; ?>">
blog category
</div>
Someone clicks the link in the block & goes to the blog. Now the visitor is on the blog category page. But the visitor wants to go back to the homepage:
<span class="return-back">back</span>
But now, it is back to the top of the homepage. I want the visitor to be back at the variable id anchor of the blog:
<div class="block wide" id="<?php echo $postid ; ?>">
How do we make this happen? I am not a PHP developer (just CSS/JS/HTML). I've used Wordpress for this project. Thank you all so much!
The format for linking to a div through url is:
mypage.com/blog#blog_id
where blog_id is the id of the div you'd like to link to.
So, assuming $postid is the id of the div you want to link back to, try this:
back
This is actually impossible to solve without rebuilding everything. The next page doesn't know what $postid is.
Related
I have looked everywhere for this question, perhaps I'm just not phrasing it correctly.
I have a page displaying various products, the table is called items. There in my fields I have all the information and images to display on the page, this works fine. Now I want to be able to press a button to add the item to cart, I have the code below where I access the data.
<div class="col-md-5">
<h2 style="font-size:25px;"> <?=$items['title'];?></h2>
<img src="<?=$items['image'];?> "width='300' height='500'/>
<p style="font-size:20px;" class = "lprice">GBP <?= $items['price'];?></p>
</div>
Now that I have done that, my question is how can I add a button for every time a result is displayed and have that button linked with that item, I appreciate this may no be as straight forward as I am phrasing this, but just looking for some help.
Thanks
You can do it in two ways, either way, you need a primary key (eg: id) in your items table which will hold a unique number for each of your items.
After that, you print your id along with everything else inside a button or inside an a tag. Like
<div class="col-md-5">
<h2 style="font-size:25px;"> <?=$items['title'];?></h2>
<img src="<?=$items['image'];?> "width='300' height='500'/>
<p style="font-size:20px;" class = "lprice">GBP <?= $items['price'];?></p>
<a class="btn btn-primary" href="add_to_cart.php?id=<?=$items['id'];?>">Add to Cart</a>
</div>
Now inside your add_to_cart.php file, you can receive the id of the products like this $product_id = $_GET['id'];
Once you have the id of the product, you can process the rest on the add_to_cart.php file and redirect the user back to the previous page with a success or error message.
This way, we passed the id using a URL parameter. The second way is to pass the id using a form. I just wanted to let you that this method exists. I hope this helps. If you have any doubt, feel free to ask in the comment section.
I have created a message system in wordpress. There s a consultation page fr each user.also a sidebar with certain menus. when the submit button is clicked the admin reviews the question and answers it. The message will be shown in the inbox sidebar menu on the same consultation page.
but whtever i tried am not getting the reply message of the corresponding user. my problem is that when i defined the link for inbox there is no id being passed.later in tht particular page whtever id s am calling its bring up the page id only and nothing else.
This is the sidebar code:
<li>
<i class="fa fa-sort-alpha-asc " aria-hidden="true"> </i> <span style="margin-left:10px;">Inbox</span>
</li>
now its bringing the id = 1. no matter which user it is.
this is the inbox code:
<?php
global $post;
$idd= $post->ID;
$title= $post->post_title;
var_dump($title);
echo "<div class= 'col-lg-4'><table style='width:500px;'><tr><td><b>Reply:</b> ".get_post_meta( $idd, 'docreply', true)."</td></tr></div>";
echo "<div class= 'col-lg-4'><table style='width:500px;'><tr><td><b>Amount:</b> ".get_post_meta( $idd, 'amount', true)."</td></tr></div>";
you can get the post id by using get_the_ID() function.
<?php
echo get_the_ID();
?>
Where is the message data saved?
I see you calling the page URL with the ID of the currently logged user.
Later, you're using the ID of the page then fetching two meta values and displaying them.
If you're using post meta, use the ID of the user that is logged in and get the meta value by using get_user_meta - https://codex.wordpress.org/Function_Reference/get_user_meta
More code would help solve this easier :)
Finally i have found a solution to my problem. I updated the post_meta values in to my user_meta and in the page where i need to display the data, i called the current user id and called the user_meta
I'm in the process of creating a website that allows people to do quizzes about different topics and for the quizzes, I have a button called Ask A Friend. At the moment, with the code I have, it doesn't display anything to press and when I click on the area where the mouse changes to a pointer, I get shown a 404 error. What I want to happen is, is a user clicks on the button, it directs them to their own friends list.
The code that I have is:
<div class="AskAFriend">
<div class="askafriend">
<a href="<?php global $current_user; echo home_url() . '/members/' . $current_user->user_login . '/friends/'; ?>">
<input class="AskAFriend_button" name="askafriend" type="button" value="Ask A Friend For Help" />
</a>
</div>
</div>
When I had it with an empty <a> tag, it displayed a button as I wanted, but with the code I have now, no button gets displaed and I get directed to a page that has a 404 error on.
I believe that it's the <a> tag that's causing the trouble.
Alright, so I'm guessing the user is logged in, and that you save the user's ID in the session. What you can do is make a page like friends.php, on there using PHP you get the user ID from the session variable, once you have that, query for all the friends of that user. This way, you have one page that will be used by all the different users.
If you are using buddypress plugin, then may be it has some conflict with other plugin. It happened with me. In my case buddypress plugin conflict with upme plugin, you have to check it first.
Try:
<a href="<?php echo bp_loggedin_user_domain . '/friends/'; ?>">
I have a link below as it is found in a particular WordPress plugin:
<a href='".home_url("?p=7&action=get_marks&id=$select_data2->id")."' ></a>
I want to auto detect page_id when I click on it to reload the same page, like:
<a href='".home_url("?p=get_id&action=get_marks&id=$select_data2->id")."'></a>
I don't want to write page id every time I create new page after putting shortcode in.
I'm assuming you are talking about server side
echo ' '
where $id is a variable that has the id
Have you considered JavaScript on the client side?
thanks for your help
i tried several method until i found the solution
here the code
global $post;
echo '<a href='".home_url("?p=$post->ID&action=get_marks&id=$select_data2->id")."'>';
where $post->ID is a variable that has the page id
thanks #user74670 you give me inspiration to solve problem
Through php i want to redirect the user to specific location :
header('Location:http://localhost/diplomska/#more')
and the url in the browser after redirect is :
http://localhost/diplomska/#more
But it still points to the home page. Even if i manualy write it in the browser, it is still the same. However, if i click the navigation link that go to the page #more , it works.
I have added data-url attribute, but still the same . Code in addition:
<div id = "more" data-role="page" data-url="http://localhost/diplomska/#more"data-title="More about you" >
And the link that work when i click on it is :
<a id="more" href="#more"
data-transation="slidedown"
data-role="button"
data-icon="arrow-d"
data-mini="true"
data-iconpos="top"
>More</a>
You can't have more than one element with a given id on a page. Remove the id from your anchor, it's href attribute references the div you want to jump to.