Dynamic page title based on url [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Hi lets say my url is www.mywebsite.com/category/music
using php how could I dynamically add a page title of the last part of the url which in this case is music. but as the the url changes how to grab the last part of that url.
At the moment im using
<?echo basename($_SERVER['REQUEST_URI']); ?>
But this shows the whole url. how can I remove specific words like "category" and remove forward slashes.
Thanks

Try this:
<title><?php echo basename($_SERVER['REQUEST_URI']); ?></title>
Or
<title><?php echo trim($_SERVER["REQUEST_URI"],"/");?></title>

Related

Get few rows from another site in PHP [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to get this url rows: https://robot.your-server.de/order/market/country/US with pagination with php and get it in my website.
Scraping is not the better thing to do, have you check if this site has an API?
If not, you can use fil_get_contents to load all the page content as a string. One you have all the HTML as a string, DomDocument can help you to navigate to the first row.
Because this is scrapping I'll not show code example.
See file_get_contents and DomDocument.

How to make an url show it? ?id=1 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to create a simple site for local test, but I need to show on URL the following:
?id=1
How can I do it?
You can do this by hyperlink, form submit, manually typing it into the URL bar and many other methods. Use a hyperlink:
ID1
Im not too sure what you are asking, but if you are looking to add an id variable to the URL you need to add it to the URL when you redirect
EX.
From link
Link

Where does the the_permalink() take you by default [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Currently I have:
Click here
This takes me to the index.php page
How do I change this in order to take me to another page?
Since you guys closed this. I will answer my own question:
The answer:
What you put in the WP_Query post_type = '(POST TYPE HERE)'
You can make a page called:
"single-(POST TYPE HERE).php
So once you click the link. This will take you to the:
"single-(POST TYPE HERE).php page
the_permalink() outputs the URL of the post currently being viewed in the loop. If you wanted to change the destination of the link then replace <?php the_permalink();?>.
Refs:
http://codex.wordpress.org/Function_Reference/the_permalink
http://codex.wordpress.org/The_Loop

Call php function using html href [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am searching for some hours today and I can not find the solution.
Here is the phpfuntion inside of the html href, which uses explode php-build-function to split the email and get the chars after #.
<a href='<?php echo afterchar('#',$nazwa_uz_l); ?>'>Log in <?php afterchar('#',$nazwa_uz_l); ?></a>
While I click the link it goes to localhost/gmail.com instead of gmail.com.
What should I do?
Try like this
<a href='http://<?php echo afterchar('#',$nazwa_uz_l); ?>'>Log in <?php afterchar('#',$nazwa_uz_l); ?></a>
The URL is relative if there's no protocol (http://) leading the URL.

Populate the URL params in title [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need help in populating the parameter in the url in the title of the page. What's the best way to do this?
www.mydns.com/sometext1/sometext2
sometext1 | sometext2
Thank you
You want to update the page's title based on the url?
document.title = window.location.pathname.split("/").slice(1).join(" | ");
window.location.pathname gives you {{/sometext1/sometext2}}
split will divide it up
slice(1) will chop off the empty index
join will put it back together
Of if you wanted to achieve this in PHP
<title>My Page<?php echo str_replace('/',' | ',substr($_SERVER['REQUEST_URI'],1)); ?></title>

Categories