{"id":50697980,"url":"https://github.com/hacklabr/wp-mvc","last_synced_at":"2026-06-09T07:35:43.463Z","repository":{"id":8612813,"uuid":"10253554","full_name":"hacklabr/wp-mvc","owner":"hacklabr","description":"MVC based WordPress theme for complex websites","archived":false,"fork":false,"pushed_at":"2014-04-10T21:45:58.000Z","size":153,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-16T01:27:32.763Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hacklabr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-05-23T21:11:35.000Z","updated_at":"2023-08-21T13:19:56.000Z","dependencies_parsed_at":"2022-08-27T17:02:20.498Z","dependency_job_id":null,"html_url":"https://github.com/hacklabr/wp-mvc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hacklabr/wp-mvc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hacklabr%2Fwp-mvc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hacklabr%2Fwp-mvc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hacklabr%2Fwp-mvc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hacklabr%2Fwp-mvc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hacklabr","download_url":"https://codeload.github.com/hacklabr/wp-mvc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hacklabr%2Fwp-mvc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34096952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-09T02:00:06.510Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-09T07:35:42.744Z","updated_at":"2026-06-09T07:35:43.458Z","avatar_url":"https://github.com/hacklabr.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## WP-MVC Theme\n\nMy experience developing in WordPress is that the callback orientation of hooks\nallow developers to design any structure to a theme, easilly turning it into a\nmess, and for the cases of complex websites, a huge mess. That way it's\ndificult to know how a theme works with WordPress.\n\nTrying to solve this problem, the proposal is to _change the WordPress behavior\nalways the same way_. This simple structure aims to be a guideline for complex\nWordPress themes with lots of queries and custom rewrite rules by relying in\nthe MVC architecture, then you can explicitly define where, how and when\nqueries are chosen and executed.\n\n### MVC architecture\n\nTranslating from the Wordpress theme dictionary, we get something like this:\n\n* Model: Custom post types and taxonomies used by the theme;\n* View: WordPress templates of the theme according to the [template hierarchy](http://codex.wordpress.org/Template_Hierarchy);\n* Controller: The [rewrite rules](http://codex.wordpress.org/Class_Reference/WP_Rewrite) and [query variables](http://codex.wordpress.org/WordPress_Query_Vars).\n\n### Post types\n\nOrganize your post types and taxonomies inside the `models` directory,\ndeclaring each one of them in its`\u003centity\u003e.php` file. All files in this\ndirectory will be automatically included.\n\n### Queries\n\nTo link queries from URLs to views you'll use the `router.php` file:\n\n1. Define a rewrite rule in the `_query_rules` function:\n        \n        return array(\n            '^sample-rule/([^/]+)/?$' =\u003e 'custom_query=$matches[1]', // sample rule\n            // another rule here\n            // one more rule here\n            // ..\n        );\n\n2. Create a variable in the `$_query` object in the `_init_query_object`\n   function:\n\n        $_query = (object) array(\n\n            // built-in template var\n            'template' = false,\n\n            // My custom query\n            'custom_query' = false,\n\n            /* other variables here ... */\n         \n        );\n\n3. Define the condition to use this variable in the `_query_processor`\n   function.\n\n        function _query_processor( \u0026$query ) {\n\n            global $_query, $post, $wpdb, $wp_query;\n\n            /* other conditions /*\n\n            } elseif ( $custom_query = get_query_var( 'custom_query' ) ) {\n\n                /* Define the template to be used. If left to false, then WordPress\n                   will choose the template */\n                $_query-\u003etemplate = 'custom-template';\n\n                /* Define a new query maybe ysing $custom_query */\n                $args = array( /* custom args */ );\n                $_query-\u003ecustom_query = new WP_Query( $args );\n\n            }\n\n        }\n\nLike this, the `custom-template.php` will be loaded with the `$_query` object\ncontaining a `$_query-\u003ecustom_query` attribute to be used.\n\n    \u003c?php global $_query; ?\u003e\n    \u003c?php wp_header(); ?\u003e\n\n        \u003c!-- lots of stuff here --\u003e\n\n        \u003c?php if ( $_query-\u003ecustom_query-\u003ehave_posts() ) : ?\u003e\n\n            \u003c?php while ( $_query-\u003ecustom_query-\u003ehave_posts() ) : ?\u003e\n            \n                \u003c?php $_query-\u003ecustom_query-\u003ethe_post(); ?\u003e\n\n                \u003c!-- post loop like any other --\u003e\n\n            \u003c?php endwhile; ?\u003e\n\n        \u003c?php else : ?\u003e\n\n            \u003cp\u003e\u003ccode\u003e$_query-\u003ecustom_query\u003c/code\u003e has no posts.\u003c/p\u003e\n\n        \u003c?php endif; ?\u003e\n\n    \u003c?php wp_footer(); ?\u003e\n\n## Rules\n\nSo, using these guidelines also implies in some rules for developers:\n\n1. Never make queries or any theme logic outside the `_query_processor`. Always\n   use an attribute of `$_query` to pass data to the templates.\n2. Always use the `$_query-\u003etemplate` attribute to define wich template will be\n   loaded, and set it in the `query_processor` to be explicit wether you want\n   WordPress to choose it or not.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhacklabr%2Fwp-mvc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhacklabr%2Fwp-mvc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhacklabr%2Fwp-mvc/lists"}