Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
faking the funk, invisible slugs
#1
I have been thinking about having slugs that dynamically output data from a plugin for various things, this is a pattern we use frequently.

Search output, blogs, category excerpts, galleries, anything dynamic.

I am not sure how some plugins do this, maybe I missed something obvious.
But
I believed there are 2 options but both boils down, you make a page where you want this to show up, basically a fake empty page, then you stick a inline shortcode in there to insert your plugins content, or the plugin uses a content filter which throws junk in your sidebar if you use getcontent, or it replaces global content on index-pretemplate hook. The page creation is usually left as an exercise left for the end user.

Most I have used involved a fake page sitting in your pages.

To have a completely fake page that does not exist you can do this. ( I beleive )
THIS WOULD ONLY WORK v3.2.1+

PHP Code:
<?php

    add_action
('error-404','outputFakePage');    

    function 
outputFakePage(){
        GLOBAL 
$id,$data_index;

        if(
$id == "fake"){
            
$data_index->title         "fake";
            
$data_index->date          "";
            
$data_index->metak         "";
            
$data_index->meta         "";
            
$data_index->url           "fake"// THIS IS THE IMPORTANT ONE TO OVERRIDE THE 404
            
$data_index->content       "fake output";
            
$data_index->parent        "";
            
$data_index->template  "";
            
$data_index->private       "";
        }    
    }
?>

edited to fix var names,thanks angryboy

discuss
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#2
This is so simple, yet so effective! Honestly, it'll save a LOT of junk page creation. Just change the properties you've got there: metak to just meta and template_file to just template (they didn't seem to work for me otherwise).

Will definitely implement this on the Message Board plugin. Thank you very much for this, shawn!
Reply
#3
The downsides, you will have to update it with other fields as they are added to core if you want to, I can modify index to accommodate missing ones in the future, also we assign all these to globals, so there is some confusion as to which are used where a global or data_index, which has been adopted by a lot of components and plugins. So we should make it standard one of these days.

Also there is the issues of menus and breadcrumbs and headers possibly not working, I am looking into all the possibilities to make this an official method of slowing dynamic slugs or making a new hook for it specifically.

For things that use page cache it's possible to add your dynamic slug into it for site maps etc. I just have not looked at it all yet.

As far as metad and template_file these are right out of index.php.
So maybe we should alias them to match the globals or make a new global object of page variables.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#4
Very interesting.
Note that this will not work with GS versions before 3.2.1.
Reply
#5
Oh yes, sorry, i have updated the main post with that and the fixed varnames
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply




Users browsing this thread: 1 Guest(s)