I've been trying to figure out how to add a php variable into my WP navigation links.
Let me explain:
I'm gonna set a cookie on the very first page of my website, when the user clicks on one of 4 types of profile:
-family
-pro
-seniors
-cadres
Currently, I have a theme switcher extension wich modifies the WP theme depending on those prefixes:
http://mywebsite.com/family
http://mywebsite.com/pro
http://mywebsite.com/seniors
http://mywebsite.com/cadres
... etc
The colors & content of the 4 "home" pages are different, but I'm using the WP navigation menu (wich remains the same on every page, so the prefixes disappear when clicking on its links).
Initially, I wanted to modify my menu links like that:
https://mywebsite.com<?php if (isset($_COOKIE['profil'])){echo '/'.$_COOKIE['profil'];} else{} ?>/navigation-link1
Here:
menu
But I can't add php here, and the solution is not ideal because it would only apply to the menu, and not the posts permalinks (I want some posts to be available regardless the profile and I don't want to duplicate all my posts).
Ideally, I would like to have a solution to set the WP theme directly based on the stored cookie. This way, it would also apply when the users click on a post permalink.
I've read things about a "walker" but I don't know what it is, wp_nav_menu_objects, but I didn't understand what files to modify nor wich code to use.
I always search the web to find my answers, but I'm french and I think my understanding has reach it's limits, so if somebody could take the time to explain to me like I'm 4 years old :), I would be grateful.
Thanks
Related
This may seem novice, but I assure its not.
So, I have a site, which displays blog posts by date from new backwards.
Standard stuff. However, what I'm trying to do is create a temporary homepage, lets call it 'yogo'. It displays some ad, or image, with a button link.
What I'd like is a direct link to the actual blog feed which displays in a given theme site's frontpage. Is it just a block?
When Im in Appearance->Reading, I can change homepage to 'yogo' fine. But, say a visitor is on 'yogo', and I want a button they click on to link to what would be the original theme frontpage with blog content, it should technically be 'Home' but is that coded somewhere through the wordpress software like the Reading mentioned above.
Maybe Im missing something, should I shut off permalinks, and dig for it in actual page extension?
Im trying to avoid using Guten. or Elem. to build out a blog page.
Any advice, thanks in advance.
Once add your code in front-page.php or home.php you can use get_the_permalink() function to get the blog page URL and will pass in "a" HTML tag like this -
Your Blog Name
Might be it can help you.
Just a quick update. actually solved this.. In simple terms, it is possible to do this really quickly through the Wpress UI. From your backend, these are the steps in the following order:
(firstly. shout out 2 user 'mirchev' because if u didn't point out templates I would of been way off. actually after about an hour of research after that) So it all takes place in Setting->Reading. From what I've read, Wpress started off as a blog based system anyways, so it was solved a long time back. Basically to start, 1. Create 2 pages, no need to add any content as long as they are 'new' and you make note of the names.
2. Also important -in the template area to the right panel when the new page editor loads up (you don't need to add any texts, images or whatever, including the area on the right just make sure "default template" is selected. 3. Afterwards, these 2 pages are 2 be used in the Setting->reading section.
What you want to do is when you enter this setting of your Wpress site, instead of having your "homepage" radio button be "latest posts" set it to 'static page,' and 4. important - select 1 of the 2 new pages you created as the static page. 5. Now, also important, for the posts page, select the 2nd of the 2 new pages you created. 6. Once this is done, what happens is your website loads the static page, which you may customize however, and then you can go into your Appearance->menus and add the appropriate link to the 2nd of the 2 new pages you created to load the blog, or link to it whichever way you choose. More often than not a menu item should appear if that is the setting you customized.
..And that is all. if fact I was very surprised just how smooth it was.
good luck ! ..--'''~~**
Separation!
Ok, here is the thing I have already added the categories to the pages (with the help of a plug-in, it's called Add category to pages) and so now I want to change the URL to display the categories (that is to say I want my pages to have this estructure: mysite.com/%categories%/%page_name% right now it has his structure: mysite.com/%page_name%), I have tried to google it but I can't find a straight answer. So if anyone has some resources (tutorials, articles) or some idea (if it's not to much to ask with code examples) on how to achieve this it would be fantastic. (And believe me, I'm asking as my last resource)
you can do it easily with "Page Parent" option available in WordPress.
Steps To create a subpage
Go to Administration > Pages > Add New screen.
In the right menu, click the “Page Parent/No Parent” drop-down/page attribute widget. The drop-down menu contains a list of all the Pages already created for your website.
Select the appropriate parent page from the drop-down menu to make the current Page a child Page.
Add content to the subpage.
Click Publish when ready.
Output - https://example.com/asia/india/
More Info. - Wordpress Subpage Permalink
well you can do this for categories and products from permalink setting, but if you want to manipulate the page url according to yourself then you need to create an blank page with the prescribed name whichever you want to insert, i.e, if you want to insert amazon within the url then create an url with name of amazon, and put the other url's under this parent page.
This way your url will look like
http://example.com/amazon/page_name
Unable to post as comment so directly posting it in an answer, in WordPress you can have custom URL. After you logged I'm as admin under dashboard you have general settings where you can put custom URL's like http://example.com/%caregory%/page_name
For more reference also checkhttp://codex.wordpress.org/Changing_The_Site_URL
I don't know if you tried this but after you login as admin, under Dashboard>>Settings>>Permalinks>>Custom Structure.
Let me know if you have already tried that.
I'm new in WordPress and trying to do the following:
I have main menu with some options (Home, File, Edit, View...). I also want to have posts. The posts can belong to different categories that match the menu options. The only last post should be displayed on Home page (Home menu option). Other older posts should be on pages under appropriate menu options.
I've searched the internet but not found the right solution.
Can I do that with WordPress?
I don't know PHP.
I don't get your question properly. As you said you don't know PHP so it will be little difficult but you can make it by custom template or editing your index page of template.
Or if you want to show 1 post(last) at your website without any php, you can go to your Dashboard->Setting->Reading and make "Blog pages show at most" from 10 to 1. But the problem is your website will show like blog. If you are using "Twenty Twelve" let me know i will make it for you.
i have a vertical menu that looks like this
HOME
NEWS
ANOTHER PAGE
- SUB PAGE
- SUB PAGE
it is retrieved via wp_list_pages. NEWS is set as my posts page in the WP backend.
what i want to achieve is getting the titles of the 3 latest posts to show up as a submenu of NEWS like so:
HOME
NEWS
- POST 3
- POST 2
- POST 1
ANOTHER PAGE
- SUB PAGE
- SUB PAGE
is there some sort of add_filter/function or even plugin to achieve this?
The problem looks as if you're trying to use a Page Object as a sort of "shell" for corresponding posts. This is probably one of the first traps a Wordpress Developer will find themselves in when developing their own themes, or working with existing code.
In short, you shouldn't use wp_list_pages if you're trying to also list Post Objects. It gets messy, and you're essentially circumventing existing methods that Wordpress provides to do exactly what you need.
What you'll want to do is look into is the built-in Navigation Menus to build out a more flexible menu. If you're using a downloaded theme, then it will almost certainly be supported. Otherwise, you'll need to look into Registering a Navigation Menu to make your theme "menu-aware".
What this will enable you to do is build a flexible menu that supports not only Pages, but also Categories and individual Posts in an intuitive UI. I would suggest deleting that Page Object called "News" altogether, and instead place the News Category in your menu alongside all of your Page Objects in whatever order you like.
As for querying the most recent three posts in your Navigation Menu as sub-menus, this will be a little more complicated to do with pure code.
What I would suggest is to look into this option first. Build out a working - albeit static - prototype to get a feel for the Menu Interface. If you're writing your own theme, replace your wp_list_pages call altogether with wp_nav_menu.
Once you get that working, open a new question to see how to write your own Nav Menu Walker to make everything display exactly how you want.
By taking this approach, you'll ensure that your theme will ALWAYS behave how you want automatically, rather than having to go in every so often to patch things up.
Let me know if this helps.
I have successfully created content types for certain pages which I have in Drupal. I have also successfully created menus for those content types, so when a user is on a certain type, for instance, Blog Article, they are presented with a certain menu. The problem is when I few all the blog articles the menu is there, but when when I few the /blog page which shows all the blog entries, the content block is gone.
I've set it up so the block will only be shown with certain content types, but there doesn't seem to be a content type of blog module in general. Is there a way around this? It is the same for the forum page. It will show for forum topics, but not for the actual forum.
I hope I've made my self clear, as it is quite hard to explain.
I do not know what version of Drupal you are using but I will try to help.
As per docs on drupal.org:
Configuring a block
Go to the Blocks overview page (Administration > Site Building > Blocks) to configure the blocks on your site. This page allows you to
drag-and-drop blocks into different regions as well as reorder the
blocks within a region.
Next to each block you can click "Configure" to change the specific block settings: Block title: Allows you to override the default title
for the block User, Role, and Page specific visibility: Adjust
visibility for block based on user, role or page. Additional settings
may also be available, depending on the particular block.
Note that blocks are configured per theme. If you change the theme or
enable multiple themes, you will need to configure blocks per theme.
Yeah. I may of messed the formatting a bit but basically, in step 2, you want to configure your block visibility by page specific visibility. It looks something like below:
Basically, I think in your case you could use that to show the blocks containing your menus on specific pages and add whatever paths you want your menu to show on.
Hope that helps! Happy coding
I figured it out. Instead of trying to display a block based on the content type you have to change it so it is displayed based on the URL. The reason for this is because the blog module which comes with Drupal 7 doesn't have a content type, so when a user arrives at http://www.example.com/blog there is no content type and throws all the blocks restricted by content type out the window.
To get around it I had to install a plugin called Pathauto. This plugin allows you to specify a default URL for a content type. Be sure to install this plugin first before creating any content as any previous URLs will not work, so you will have to manually go back and change the URL alias.
Once you have installed the Pathauto plugin go and setup your paths for content types. I set it up so anything which is a derivative of the content type "Blog Entry" is given the URL /blog/post-name
Now all you have to do to set the block is go to the block and click configure. In the section Pages make sure you select "Only the listed pages". You'll have to type two lines. blog and blog/*
Now that you have set this any new content which is created as Blog Entry will fall under this URL expression and the block will be shown.
Works like a dream now. What a headache to get working.