wordpress / php help
- Started
- Last post
- 30 Responses
- dbloc
I am using this to return the name of the page in WP
<.?php echo $wp_query->queried_object->post_name
?>now I want to take the submissions part off of it and return only:
second-events-test
anyone have any idea how to do this?
- dbloc0
the current return is
second-events-test-submissions
- ArmandoEstrada0
Stupid question, but what exactly is the post title?
- dbloc0
page title is
second-events-test-submissionsI want to get
second-events-test
- mikotondria30
I think you might be able to massage the use of:
http://php.net/manual/en/functio…
split the string by "-", implode all expect the -1th element, etc..- I suck at php..I don't even know where to begin with this...dbloc
- mikotondria30
http://pastebin.com/n7UL1jsj
might help.
if it doesn't, just echo it at out at each line see what's happening.
Basically, we split the string up into an array where each element is what's between the "-"s. Then we array_pop the last element off the end of the array, this should be the "submission" part, then we implode (glue back together) the array elements into a string, and use "-" as the 'glue'. Hope that makes sense, even if the actual code (untested) doesn't.- obviously echo $mynewlink out at the end.mikotondria3
- ps: Go to bed !mikotondria3
- Ha Haa. It's only 11pm over here.dbloc
- Thanks for the help...testing it out now.dbloc
- dbloc0
Warning: implode() [function.implode]: Invalid arguments passed in /home/content/m/a/x/html/blog/wp... on line 11
- vwsung18t0
is this for the permalink? If so, you can use this: http://wordpress.org/extend/plug…
- Jacque0
Is this submissions page a sub-page of a page titled "second-events-test"?
If so, you could use something like:
if ($post->post_parent) {
$foo = get_the_title($post->post_parent...
}... to get the pages parent (if one exists).
- dbloc0
^ It's not. The events section is actually part of the blog using only the events category and the submission page is an actual page.
- BattleAxe0
Why not just edit your permalinks right before you publish , usally under your post title you can edit the name of the permalink to just about anything
as for exisiting post you can edit those names too but will kill linkbacks
- dbloc0
need it to be dynamic. There will be dozens of events.
- dbloc0
This thread got a little rerouted. All I really want to do is echo the page name or end of url minus "-submissions"
second-events-test-submissions
to
second-events-test
- dbloc0
all events will be different names so I just need to grab what is in between the last two slashes minus '-submissions'
- dbloc0
trying not to have to use a custom field just for the event name.
- vaxorcist0
? maybe I don't get something.. but is it like :
$foo = "second-events-test-submissions...
$foo = str_replace("submissions","",$fo...print $foo;
second-events-test
- vaxorcist0
sorry... http://pastebin.com/5H3kvryF
- either this is really easy, or I don't get something....vaxorcist
- dbloc0
vaxorcist you are the man...thank you so much. exactly what I was looking for...worked like a charm.
Thanks everyone else too.
- dbloc0
used this to grab the current name
$wp_query->queried_object->post...and then used str_replace