简体   繁体   English

如何在我的 Wordpress 站点的每个页面上包含一个菜单?

[英]How do I include a menu on every page on my Wordpress site?

I have a Wordpress site that uses an index.php that contains a menu structure that appears only on the index.我有一个 Wordpress 站点,该站点使用 index.php,其中包含仅出现在索引上的菜单结构。 I'd like to add that menu selection to each page.我想将该菜单选择添加到每个页面。 The menu is executed with javascript.使用 javascript 执行菜单。

                        <div class="filternav" id="maintabs">
                            <ul>
                                <li><a id="newsid" href="javascript:showonlyone('news');" title="View Latest Activity" class="active">Latest</a></li>
                                <li><a class="" id="outlineid" href="javascript:showonlyone('outline');" title="View Course Outline">Outline</a></li>
                                <li><a id="assignmentsid" href="javascript:showonlyone('assignments');" title="View Only Assignments" class="">Assignments</a></li>
                                <li><a class="" id="linkstextsid" href="javascript:showonlyone('linkstexts');" title="View Links & Media Resources">Resources</a></li>
                                <li><a id="peopleid" title="View by People" href="javascript:showonlyone('people');" class="mpix">f</a></li>
                            </ul>
                        </div>

Clicking "Outline" on the index.php page lists all posts categorized with that id.单击 index.php 页面上的“大纲”会列出所有按该 ID 分类的帖子。

Is there anyway to create href links on subpages to execute the javascript when the links are clicked on subpages.无论如何,在子页面上单击链接时,是否可以在子页面上创建 href 链接以执行 javascript。

The function is function 是

function showonlyone(thechosenone) {
                 $('div[name|="pane"]').each(function(index) {
                      if ($(this).attr("id") == thechosenone) {
                            $(".filternav a").removeClass("active");
                            $("#"+thechosenone+"id").addClass("active");

                           $(this).fadeIn(150);
                      }
                      else {
                           $(this).fadeOut(150);
                      }
                 });
            }

I've tried adding these elements to the page.php我试过将这些元素添加到页面中。php

Is it your custom theme or are you editing some existing one?这是您的自定义主题还是您正在编辑一些现有主题? Check the WP template hierarchy docs .检查WP 模板层次结构文档 There is a list of PHP files with their backup template files.有一个包含 PHP 个文件及其备份模板文件的列表。

If your theme contained only the index.php , it would be sufficient to put your code only in there.如果您的主题仅包含index.php ,则仅将您的代码放在那里就足够了。 Usually though you'd need to include it also in single.php , page.php , archive.php , search.php and home.php (and probably more).通常,尽管您还需要将其包含在single.phppage.phparchive.phpsearch.phphome.php (可能还有更多)中。

One of the possible approaches would be creating menu.php file and then including it in all files needed using include() .一种可能的方法是创建menu.php文件,然后使用include()将其包含在所有需要的文件中。 Another option would be putting the menu to header.php or footer.php as these are already included in all files metioned.另一种选择是将菜单放入header.phpfooter.php ,因为这些已包含在所有提到的文件中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在wordpress页面上的html表单中包含PHP? - How do I include PHP in my html form on a wordpress page? 随机 Java 脚本不断在每个页面上添加我的 WordPress 站点我应该如何删除它们? - Random Java Scripts keep adding my WordPress site on every page how should i remove them? 如何将我的WordPress网站主页重定向到目标网页,同时允许网站的其余部分不受影响? - How do I redirect my WordPress site homepage to a landing page, while allowing the rest of the site to remain unaffected? 如何获得自定义的右键单击上下文菜单以显示指向我网站上页面的两个链接? - How do I get a custom right-click context menu to show two links to a page on my site? 如何将此Javascript添加到我的wordpress网站? - how do I add this Javascript to my wordpress site? 我是否必须在每个网页中都包含我所有的头部内容? - Do I have to include all of my head content in every single web page? 如何先加载所有站点菜单和其他文本内容,然后再在Wordpress中加载图像? - How can I load all my site menu and other textual content first and then load images in wordpress? 如何使搜索框链接到我页面上的网站? - How do I make a search box link to a site on my page? 如何在分页中突出显示当前页面菜单? - How do i keep my current page menu highlighted on pagination? 尝试将菜单页面添加到WordPress管理站点 - Trying to add a menu page into WordPress admin site
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM