Posts: 9
Threads: 1
Joined: Sep 2016
2016-09-06, 22:24:52
(This post was last modified: 2016-09-07, 06:22:57 by mica.)
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
Posts: 6,266
Threads: 181
Joined: Sep 2011
Is gallery your page id ?
eg.
website.com?id=gallery
Posts: 9
Threads: 1
Joined: Sep 2016
(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
Posts: 6,266
Threads: 181
Joined: Sep 2011
ok so the plugin is already doing its own routing parsing.
hmm
Posts: 9
Threads: 1
Joined: Sep 2016
2016-09-07, 00:42:01
(This post was last modified: 2016-09-07, 00:43:27 by mica.)
(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
Posts: 6,266
Threads: 181
Joined: Sep 2011
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
Posts: 9
Threads: 1
Joined: Sep 2016
2016-09-07, 03:29:33
(This post was last modified: 2016-09-07, 05:18:26 by mica.
Edit Reason: mistake about the plugin name
)
(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 ?
Posts: 6,266
Threads: 181
Joined: Sep 2011
did you try
gs-front-router I linked
That plugin you linked asks to change the rewrite rules, which is not necessary, and confusing.
Posts: 6,266
Threads: 181
Joined: Sep 2011
actually I wouldn't recommend that one either now that i look at it. Looks buggy.
Posts: 538
Threads: 12
Joined: May 2013
2016-09-07, 04:22:53
(This post was last modified: 2016-09-07, 04:24:47 by Bigin.)
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
Posts: 6,266
Threads: 181
Joined: Sep 2011
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.
Posts: 9
Threads: 1
Joined: Sep 2016
(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
Posts: 9
Threads: 1
Joined: Sep 2016
(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.
Posts: 538
Threads: 12
Joined: May 2013
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
Posts: 9
Threads: 1
Joined: Sep 2016
(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) ?
CTRL+Z / +Z on this forum will be apprecied
Posts: 538
Threads: 12
Joined: May 2013
(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);
Posts: 9
Threads: 1
Joined: Sep 2016
2016-09-07, 05:31:42
(This post was last modified: 2016-09-07, 05:35:06 by mica.)
(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) ?
CTRL+Z / +Z on this forum will be apprecied
Posts: 538
Threads: 12
Joined: May 2013
(2016-09-07, 05:31:42)mica Wrote: do you have the same version 3.3.11 ? Plugin gs-front-router (latest from github v0.3) ?
GS 3.3.8
Plugin 0.3
Posts: 538
Threads: 12
Joined: May 2013
Are you use get_page_content(); in your theme?
Posts: 9
Threads: 1
Joined: Sep 2016
(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 !
CTRL+Z / +Z on this forum will be apprecied
Posts: 6,266
Threads: 181
Joined: Sep 2011
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";
?>
|