wordpress - Create custom menu in php based on pagenames -
im trying make custom hardcoded menu in wordpress page-template. site has 3 pages (1, 2, 3) , @ page 1 wish loop trough pages has page1 pagetemplate , 2 2 etc.
how can loop trough , names of pages can put them in menu?
if example visit page 1 , pages has page1 template (parent) "visit us" , "read more" menu this:
-visit -read more
but if go page 2 menu might this:
-funpark -foobar
now if add new page "1" parent , name page "about" new menu show
-visit -read more -about
cheers, emil
you can query pages , template value. codex says:
the filename of page's assigned custom template stored value of custom field named '_wp_page_template' (in wp_postmeta database table). (custom fields starting underscore not display in edit screen's custom fields module.)
this means can build page query this:
$args = array( 'post_type' => 'page', 'meta_query' => array( array( 'key' => '_wp_page_template', 'value' => '[your template goes here]' ) ) );
all have loop through pages, permalink , build menu.
Comments
Post a Comment