Hello there!
I'm trying to extend an existing plugin (
ExtraGallery). to make a specific portfolio.
For now, succeed to every modifications I made. But I'm stuck to basic
routing problem :
How to create a route that use a specific template via
http://website.com/gallery/galSlug/ or
http://website.com/?gallery=galSlug
The original plugin provide a function to retrieve all galleries or a single (via parameter)
Do you have some exemple of routing (other plugins e.g) where I can understand how to do that ?
Thanks in advance.
mica
Is gallery your page id ?
eg.
website.com?id=gallery
(2016-09-06, 23:48:31)shawn_a Wrote: [ -> ]Is gallery your page id ?
eg.
website.com?id=gallery
Hi Shawn
Nope, for now the plugin doesn't create pages
ok so the plugin is already doing its own routing parsing.
hmm
(2016-09-07, 00:38:00)shawn_a Wrote: [ -> ]ok so the plugin is already doing its own routing parsing.
hmm
mhmmm no, this is my question, the plugin provide only a function to retrieve gallery
So I need to know how to implement the routing
Is there any other plugin that make routes?
Thanks in advance
(2016-09-07, 01:09:59)shawn_a Wrote: [ -> ]I do not think there is. I think there is code floating around the forum though.
eg
http://get-simple.info/forums/showthread.php?tid=8254
Ok thanks a lot, it seems that it's exactly I needed but after many attempts I still have 404
Original pages work
http://localhost/siegen/about √
but
http://localhost/siegen/projet/abc = 404 X
here are some info about my config
fancy url are
on && (cache flushed many times)
no custom permalink specified
in the
Extra Router GS FRONT ROUTER plugin setting page
Route : SITEURL/projet/([a-z0-9-]+)
Action :
PHP Code:
<?php
die('test');
return array(
'title' => 'test (' . $args[0] . ')',
'content' => function($slug) {
echo $slug;
}
);
And finally (I think the problem is here) my
.htaccess rewrite content
Code:
RewriteEngine on
RewriteBase /siegen/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#Extra Router recommended (doesn't work)
#RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
#original (doesn't work)
#RewriteRule /?([A-Za-z0-9_-]+)/?$ index.php?id=$1 [QSA,L]
#my attempt (doesn't work ;(((((
RewriteRule /?([^/]*)/?(.*)/?$ index.php?id=$1&pid=$2 [QSA,L]
Could you help me, please ?
did you try
gs-front-router I linked
That plugin you linked asks to change the rewrite rules, which is not necessary, and confusing.
actually I wouldn't recommend that one either now that i look at it. Looks buggy.
Create new route:
galleries/([a-z0-9-/]+) in gs-front-router, for example
Action:
Code:
<?php
return array( 'title' => 'My Title',
'content' => function($slug) {
echo 'This is my Gallery' .$slug;
});
that should do the trick.
http://mysite/galleries/abc/
http://mysite/galleries/def/
everything working
That plugin uses namespaces and anonymous functions closures, so you might have problems on php 5.2
other than that it seems to work well, it will also not work with 3.4 without modification.
(2016-09-07, 04:22:53)Bigin Wrote: [ -> ]Create new route: galleries/([a-z0-9-/]+) in gs-front-router, for example
Action:
Code:
<?php
return array( 'title' => 'My Title',
'content' => function($slug) {
echo 'This is my Gallery' .$slug;
});
that should do the trick.
http://mysite/galleries/abc/
http://mysite/galleries/def/
everything working
Thanks Bigin, it start working I got The Title
but the content is empty and when I try
'title' => 'My Title'.$slug,
I got only My Title, And of course I need this $slug
here is my action code
PHP Code:
<?php
$slug=$args[0];
return array( 'title' => 'My Title '.$slug, // works ;)))
'content' => function($slug) { // doesn't work ?????
echo 'test '.$slug;
});
Thanks in advance to both of you guys
(2016-09-07, 04:49:15)shawn_a Wrote: [ -> ]That plugin uses namespaces and anonymous functions closures, so you might have problems on php 5.2
other than that it seems to work well, it will also not work with 3.4 without modification.
Yep, I've some problems even in php 5.6 (GS3.3) with the solution of Bigin : the title work but like the 'content' => doesn't show anything.
But this feature (routing) is important for plugins development, don't you think ?
Is there another solution to show my galleries ? I can dynamically generate a page with a component each time a gallery is created/saved but I found this way a messy and also hard to maintain.
put $slug = get_page_slug(false); in your functions.php file in theme directory. Or you can use get_page_slug(false) in your anonymous functions
(2016-09-07, 05:20:28)Bigin Wrote: [ -> ]put $slug = get_page_slug(false); in your functions.php file in theme directory. Or you can use get_page_slug(false) in your anonymous functions
nope ;(
both doesn't work. It looks like 'content' table key change in my version (3.3.11) ?
(2016-09-07, 05:24:33)mica Wrote: [ -> ] (2016-09-07, 05:20:28)Bigin Wrote: [ -> ]put $slug = get_page_slug(false); in your functions.php file in theme directory. Or you can use get_page_slug(false) in your anonymous functions
nope ;(
both doesn't work. It looks like 'content' table key change in my version (3.3.11) ?
Turn debug on in your config.php file, to see messages:
define('GSDEBUG', TRUE);
(2016-09-07, 05:28:37)Bigin Wrote: [ -> ]Turn debug on in your config.php file, to see messages:
define('GSDEBUG', TRUE);
Already
done √
No messages ;(
do you have the same version 3.3.11 ? Plugin gs-front-router (latest from github v0.3) ?
Are you use get_page_content(); in your theme?
(2016-09-07, 06:03:02)Bigin Wrote: [ -> ]Are you use get_page_content(); in your theme?
Yep ; )
Ok guys I made a fresh install and the solution of Bigin works there. Probably too much plugins added/removed on my local version
here is the final code
route :
galleries/([a-z0-9-/]+)
action :
PHP Code:
<?php
return array( 'title' => 'My Title '.$args[0],
'content' => function($slug) {
get_page_slug(false); (now if I comment this line it still work)
echo 'This is my Gallery ' .$slug;
});
Thank you to both of you for your time and the sharing of your knowledge !
Not sure why he is using a callback for content, there, very confusing.
Plugin is also setting data_index after all the globals are set so it is pretty much useless.
If you want to set all your variables you need to set globals, you can also just echo your content, since the plugin is also doing a ob_get_contents ( it looks like you can match a bunch of routes and it aggregates all the content togather ) but this does not actually work atm, because he is only using data_index->content not global $content..
I honestly have no idea how the above code even works, it only works because of references which is bad.
so as long as you understand these problems it works well.
personally id stick with the globals.
PHP Code:
<?php
GLOBAL $title,$content;
$title = "MY TITLE";
$content = "MY CONTENT";
?>