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.
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!
I'm making a website in WordPress, and I'm using a plugin ACF PRO. I'm doing the entire site with flexible content, so the WordPress site is like a page builder.
Everything is fine, however, I came to a point where I need to have same functionality for single-[custom-post-type], so I can "Add row", header, footer etc... on it, but I can't figure out on how to do it.
I know that it's possible, because e.g if you look at this site here: https://rolleragency.co.uk/our-projects/
You can see that it works. I know they are using flexible content because I worked on that site and I did there what I wanted. I can't remember how to do that.
I think I had to use a Tempate Page? Or? I can't remember.
THe site is built entirely on flexible content, so everything there is modular and it's like a drag and drop, but how do I do that on single-slug?
You have to create a page template, yes.
So something like page-projects.php then in WordPress admin you would have a page called Projects.
The template you created should be automatically applied to this page. If it doesn't for some reason you can choose which template WP should use on the right side when editing a page.
Now, you can add whatever code you need to the page-projects.php. And also any fields you may need for that page you can set up in ACF by telling ACF to apply those fields to pages that use projects template.
This is how I would and did do it on several occasions :)
I'm still learning Drupal, but I'm completely stuck at this point. I need to create a template for the child pages based off the navigation link clicked.
This grid is a Bootstrap thumbnail grid serving as a navigation menu. I want to know how to create a template page based off the parent navigation menu item. Each page will have the same format based off this menu.
It's unclear what you're trying to achieve, but as far as I can tell, you might need to start by trying to identify what those pages are and what parts they consist of (views, blocks/regions, nodes etc.) and then theme accordingly. Take a look at a diagram here https://www.drupal.org/docs/7/theming/overview-of-theme-files to get a better idea of how this all works together.
Once you know what you're dealing with, look for customization options. It can be anything from theme settings to views configuration, working with css, blocks, custom page/node templates (see here https://www.drupal.org/docs/7/theming/template-theme-hook-suggestions) etc.
If you need more info - please provide more detail, like links/screenshots of the pages that you need new templates for as well as explanation of how those 'templates' will need to look like
So basically once you choose The book menu item "Topics", you arrive to the topics page with the navigation menu (shown in the screen shot above).
When you choose one of the images in the thumbnail gallery (first screen shot), you are supposed to arrive to the child page for that menu item chosen (sub book page). All the sub book pages (are supposed to have the same format displayed in this basic sketch screen shot displayed below).
So for that, I am required to make a template for these sub book pages.
I just realized too that these sub pages would probably share the same parent of topic, so most likely, I have to create a template based off the action that "topics" = parent page ?
Screen shot of sub child page for topic chosen/ sub book page
thank you for your patience guys!
Okay, after working with my new partner, we discussed trying to create a view that will have headers:
<h1>**Topic Overview**</h1>
[user content input under title] <br><br>
<h1>**News and Initiatives**</h1>
[user content input under title] <br><br>
<h1>**Resources**</h1>
[displayed depending on tag chosen to display]
We just cant figure out how do we keep these headers constant, but allow the content to change, or be changed for every sub nav item (child page from nav menu above).
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
How to find where my page titles exists in my database and how to merge with my menus? Maybe I can easily change them using phpmyadmin?
I found that Apearance->Menus is a nightmare when i have more than 40+ menu items. I want to get a workaround idea?
The menu items in the list are derived from each page's title. If you want to create a custom menu editor, use wp_nav_menu. It also helps to make sure that you set each page's parent page.
It might pay to look for a menu editor plugin, as I am sure they exist (No I havn't looked).