Why aren't my Wordpress menu items showing the pages to which they link? - hyperlink

I'm adding a custom menu, using this code to register the menu:
add_action( 'after_setup_theme', 'register_custom_menu' );
function register_custom_menu() {
register_nav_menu( 'primary', __( 'Main Menu' ) );
}
And this code to display the menu:
<?php wp_nav_menu( array(
'theme_location' => 'header-menu',
'container_class' => 'header-menu',
) );
?>
The Problem:
The menu is registered. I can create it. I can save it. It displays on the web page.
It does not display the page to which it is linked. The address bar will show, for example, "http://localhost:8888/sample-page/" but it isn't displaying that page, it stays on the home page.
There are no error messages.
Where do I start to look for the problem?

Related

How to press an <a> link with zombie.js?

I am using behavior driven development with cucumber-js, and trying to write a test to follow a link, and I have the following code:
When I click "Add page"
this.When(/^I click "([^"]*)"$/, function(link, callback) {
this.browser.pressButton(link, callback);
});
Add page is a link button:
<button>Add page</button>
The idea that the zombie rest on the same page after pressing the button, is there an other way ?
The function pressButton is used to press a button the page.
For clicking a link on a page use clickLink function.
So your code should be:
this.When(/^I click "([^"]*)"$/, function(link, callback) {
this.browser.clickLink(link, callback);
});

Firefox addon opens tab with content, copy/paste of the tabs url will not load page fully

I have an addon that places an ActionButton on the toolbar. When the ActionButton is clicked the code below is run.
The code opens a new tab and provides some html and js, this acts as the addon's UI.
The url of the new tab is:
resource://jid1-qljswfs6someid-at-jetpack/addon-firefox/data/html/view.html
If I copy/paste that url into another new tab manually, the html displays but the js logic is not loaded. Is there a way to do this without clicking the ActionButton? So I could maybe bookmark the addon instead of having the ActionButton take up space.
Code:
Tabs.open({
url: require("sdk/self").data.url('html/view.html'),
onReady: function onReady(tab) {
worker = tab.attach({
contentScriptFile: [
require("sdk/self").data.url.get('lib/lib1.js'),
require("sdk/self").data.url.get('js/lib1.js')
],
onMessage: function(message) {
console.log('stuff done');
}
});
}
});
In order to run it whenever the site from data.url('html/view.html') is loaded you would have to use page-mod instead of manually attaching to the document to the tab.
Your include pattern would be something like data.url('html/view.html') + "*", so it also attaches to the page if there is a hash or a query to the document.

Displaying page Name in the URL instead of page ID in yii?

How to display Page Name in the url instead of Page ID
For example, It Should be
localhost/mysite/index.php/page/about
Instead of
localhost/mysite/index.php/page/1
I have tired from edit actionview()
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}
You can create links to ANY url that you like. The issue is how you deal with the data that is passed.
So in your view, create a link.
About Us
This will call the controller action actionView(). You can then handle the page in there.
public function actionView($page)
{
// Load the model with the required page tag.
$pageDetails = Article::model()->findByAttributes(
array('page_name' => $page)
);
// Display the page
$this->render('view',array(
'model'=>$pageDetails
));
}
Updated Answer
Hope you are making your website SEO friendly with pretty URL. If your pages are static web pages such as about, faq, privacy..., you can implement the above answer provided by crafter. In this case page names should unique.
Another way (but not exactly what you want) is url rewriting with native yii feature urlManager. In this case page id will appear in URL like bellow.
localhost/mysite/index.php/page/1/about
localhost/mysite/index.php/page/2/britain-to-support-italys-intelligence-effort-on-migrants
If you observe, most of the News website following the same url structure.
Ex: http://www.telegraph.co.uk/finance/economics/11682277/Greeks-admit-they-will-default-at-the-end-of-the-month-as-central-bank-turns-on-government.html
To do this this in application, you have to write urlManager rules.
'urlManager' => array(
'urlFormat'=>'path',
'showScriptName'=>true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
//We are adding pretty url for article
'page/<id:\d+>/<title:[a-zA-Z0-9\-_]>' => 'page/view',
),
I am assuming bellow is you Article database table
id title description keywords status
-------------------------------------------------------
1 about some big text some keys active
Now i am making the URl dynamically
<?php
//In Controller
//Fetch articles and send them to view
$articles=Articles::model()->findAll();
?>
<?php
//In View
//Iterate articles
foreach($articles as $article)
{
$id=$article->id;
$title=$article->title;
//Make structured Url.
// Replaces all spaces with hyphens and change text to lowercase .
$titleInUrl= strtolower(str_replace(' ', '-', $title));
// Removes special chars.
$titleInUrl=preg_replace('/[^A-Za-z0-9\-]/', '', $titleInUrl);
?>
$title
<?php
}
?>
You can also change URL pattern as you want. Ex i need url like
localhost/mysite/index.php/page/about-1
For this i have write/change rule in urlManager as
'page/<title:[a-zA-Z0-9\-_]>-<id:\d+>' => 'page/view',
Hope it will help you for your problem.

Yii appending new route to the exisitng route in url with Yii-bootstrap but working fine with CMenu

am actually having some issue with url routing while using TbMenu widget,i am using the format of /moduleId/ControllerId/ActionId in accessing module Controllers,here is an example
<?php $this->widget('bootstrap.widgets.TbNavbar', array(
'type'=>'inverse', // null or 'inverse'
'brand'=>'mysite',
'brandUrl'=>'#',
'collapse'=>true, // requires bootstrap-responsive.css
'items'=>array(
array(
'class'=>'bootstrap.widgets.TbMenu',
'items'=>array(
array('label'=>'Home','url'=>array('/site/index'), 'active'=>true),
array('label'=>'About', 'url'=>array('/site/page')),
array('label'=>'Contact us','url'=>array('/site/contact')),
),
),
'<form class="navbar-search pull-left" action=""><input type="text" class="search-query span2" placeholder="Search"></form>',
array(
'class'=>'bootstrap.widgets.TbMenu',
'htmlOptions'=>array('class'=>'pull-right'),
'items'=>array(
array('label'=>'Sign in', 'url'=>'/user/auth','visible'=>Yii::app()->user->isGuest),
'---',
[b] array('label'=>'Profile', 'url'=>'/user/user','visible'=>!Yii::app()->user->isGuest, 'items'=>array([/b]
[b]array('label'=>'Settings', 'url'=>'user/user/index'),[/b]
[b]array('label'=>'Logout', 'url'=>'user/user/logout')[/b],
)),
),
),
),
he three last line are the ones that are causing problem,when i try to access those links after clicking on home,page,contact us(using the Site controller actions that are auto-generated by the Yii) the route is appended to the existing url in stead of creating a new url to the module,for example if am on home page(after clicking home it has this as url localhost/mysite/index.php/site/index)**it gives me this url localhost/mysite/index.php/site/index/user/user/index,if i go the same link again with this as url it gives me **localhost/mysite/index/user/user/index/user/user/index if i click again it add another one again and again..but the strange in all is that it works fine with CMenu,here is snippet of CMenu that works fine,
<?php $this->widget('zii.widgets.CMenu',array(
'items'=>array(
array('label'=>'Home', 'url'=>array('/site/index')),
array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),
array('label'=>'Contact', 'url'=>array('/site/contact')),
array('label'=>'Login', 'url'=>array('//user/auth'), 'visible'=>Yii::app()->user->isGuest),
array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('//user/user/logout'), 'visible'=>!Yii::app()->user->isGuest),
array('label'=>'My profile ', 'url'=>array('/user/user/'), 'visible'=>!Yii::app()->user->isGuest),
),
)); ?>
i am assuming that it might be caused by the fact that those links are submenu but i am not sure since the first in those links is not submenu and has the same problem!thank you again
The TbMenu component is using CHtml::link to display the links...
CHtml::link(label, url, options)
CHtml::link method has one check
if url is an array ... then use controller->createUrl(...) method
if url is a string ... then just return that string.
So, I think, #dInGd0nG suggestion would work.
if not then you should be using array ...something like ( don't forget to prefix / )
array('label'=>'Settings', 'url'=> array('/user/user/index') ),
array('label'=>'Logout', 'url'=> array('/user/user/logout') )

jQuery UI dialog form, not sending correct variable

I'm loading a customer info page using jQuery. There's a list of customers with a link next to it:
View
That triggers this function:
function load_customer(id) {
$("#dashboard").load('get_info/' + id);
}
That works perfectly. On the page I'm loading, I have a jQuery UI modal dialog form for adding new information.
<div id="addinfo">
<form><input type="hidden" name="customer_id" value="<?php echo $c->id; ?>" /></form>
</div>
My javascript:
$("#addinfobutton").click(function(){
$("#addinfo").dialog("open");
return false;
});
$("#addinfo").dialog({
autoOpen:false,
width:400,
height:550,
modal: true
});
When you select a customer the first time, it populates the hidden field correctly, but then it stays the same even after selecting other customers.
I thought that by loading a new customer page, the form would reset as well... but apparently it's being stored/cached somewhere. If I echo the ID anywhere else in the page, it shows correctly... just not in the "addinfo" div.
Any help/suggestions would be appreciated! Thanks!
JQuery dialog's dont reload the content for you when you open them. I tend to have an AJAX call replacing the content of the div that the dialog is on (or tweakng some values in it) when the dialog is opened.
If you want a hidden field, then I wouldn't put it within the dialog, you should be able to retrieve the value from outside the dialog.
After some more researching, it seems the dialog is being cached client-side after it's called. So to get around that, I just added the customerId to the end of the popup div's ID name... so each customer page will have a unique dialog ID.
However, if it's caching each of those dialogs, won't there be a performance loss if you open quite a few? How can you clear them without having to do a full page refresh?
I guess if the #addinfo div is updated it should capture the new content...anyway this would destroy the dialog after closing it to insure a new instance will be created:
$("#addinfobutton").click(function(){
openDialog('#addinfo');
return false;
});
function openDialog(elm) {
$(elm).dialog({
autoOpen:true,
width:400,
height:550,
modal: true,
close: function() {
$(this).dialog('destroy');
}
});
}

Resources