ciaravino
Forum Replies Created
-
Okay, thanks.
Thanks!
I just had to add/change a few things. I had to make it so the original get_pages only listed pages whose parent was /games/ so I didn’t get duplicate listings from the main get_pages and then from the child get_pages. In the above code you just gave me I also just added sort_column=menu_order. Last, I put that code at the bottom of the original $my_pages foreach.
EDIT: It’s starting to look good. Thanks a lot, you’ve helped a ton :D. I’m putting everything in a table instead of ul. I’d like users to be able to filter the data, can you point me in the right direction if I wanted to accomplish it? Like a tutorial or something.
Also, do you know of any WordPress functions for finding the number of children or grandchildren of a page? I’ve looked but I didn’t see anything. I’d like to be able to list a number of games and expansions, if possible.
I don’t have any code for expansion links yet. They are just being displayed with all the normal game pages.
If I use:
$html .= '<ul>'; $html .= wp_list_pages("title_li=&child_of=".$pag->ID."&echo=0"); $html .= '</ul>';
will the expansion links be displayed with the normal links? Because I still want them to be listed with the normal game links, just under them and in the correct order, like this: https://mac.gamingapple.com/esrb-ratings/teen/ it keeps the hierarchy.
EDIT: I just used:
$html .= '<a href="' . get_page_link($pag->ID) . '" '; $html .= 'title="read more about: ' . $pag->post_title . '" >';
And it works for getting me the proper links! ?? I’m still looking for the solution to the ordering though. I’m trying wp_list_pages.
EDIT 2: I tried using wp_list_pages instead of get_pages but it gave me an error on my foreach statement. Is there something I can do to just target grandchildren of a page? Like, make it so every grandchild gets displayed as not ASC alphabetical, but menu_order without affecting the child pages?
function get_my_meta(){ $html= ''; if (get_bloginfo('description') == "Mac") { $gamesid = 15; } $my_pages = get_pages('child_of='. $gamesid . '&depth=1&echo=0&sort_colum=menu_order'); $getesrbrating = get_post_meta($pag->ID, 'ESRB Rating', true); $esrbratingreplace = str_replace(" ", "-", $getesrbrating); $getdeveloper = get_post_meta($pag->ID, 'Developer', true); $developerreplace = str_replace(" ", "-", $getdeveloper); if(!empty($my_pages)){ $html .= '<ul>' . "\n"; foreach ($my_pages as $pag) { $getgame = $pag->post_title; $gamereplace = str_replace(" ", "-", $getgame); $getesrbrating = get_post_meta($pag->ID, 'ESRB Rating', true); $esrbratingreplace = str_replace(" ", "-", $getesrbrating); $getdeveloper = get_post_meta($pag->ID, 'Developer', true); $developerreplace = str_replace(" ", "-", $getdeveloper); $releasedate = get_post_meta($pag->ID, 'Release Date', true); $esrbrating = '<a href="https://' . get_bloginfo('description') . '.' . 'gamingapple.com/esrb-ratings' . '/' . $esrbratingreplace . '">' . get_post_meta($pag->ID, 'ESRB Rating', true) . '</a>'; $developer = '<a href="https://' . get_bloginfo('description') . '.' . 'gamingapple.com/developers' . '/' . $developerreplace . '">' . get_post_meta($pag->ID, 'Developer', true) . '</a>'; $html .= '<li><a href="https://' . get_bloginfo('description') . '.' . 'gamingapple.com/games' . '/' . $gamereplace . '">' . $pag->post_title . '</a>'; $html .= ($releasedate != '') ? '<span class="releasedate">' . $releasedate . '</span>' : ''; $html .= ($esrbrating != '') ? '<span class="esrbrating">' . $esrbrating . '</span>' : ''; $html .= ($developer != '') ? '<span class="developer">' . $developer . '</span>' : ''; $html .= '</li>'. "\n"; } } $html .= '</ul>' . "\n"; return $html; }
To get links for things, I’m using their title and replacing all the spaces with hyphens, lol. I’m sure there is a better way, but this is what I came up with. It’s your original code.
The main problem I’m having is I don’t know how to get a variable for the actual game’s title in the links for expansion games, and how to tell WordPress when one of the links should be an expansion (meaning it’s a grandchild of /games/)
Another problem is that the list isn’t displaying the game expansions in “menu_order”. For example, at the very bottom of the page (if you look at the live https://mac.gamingapple.com/games/), you see World of Warcraft followed by Cataclysm, The Burning Crusade and Wrath of the Lich King. The problem is Cataclysm’s menu_order is 3 because it’s the newest World of Warcraft expansion, therefore it should be last in the list. The Burning Crusade is 2 because it’s the 2nd expansion, etc. This page is currently displaying all of the game pages in alphabetical order, which I want. But, I don’t want the game expansions to be ordered alphabetically, I need them ordered by menu_order. The expansions are any games that are grandchildren of the /games/ page.
In that image, when I hover over Wrath of the Lich King, I get https://mac.gamingapple.com/games/wrath-of-the-lich-king but I need it to be https://mac.gamingapple.com/games/world-of-warcraft/wrath-of-the-lich-king since Wrath of the Lich King is an expansion of World of Warcraft, so I have it as a child of the World of Warcraft page.
WordPress automatically forwards the user to https://mac.gamingapple.com/games/world-of-warcraft/wrath-of-the-lich-king once they click on https://mac.gamingapple.com/games/wrath-of-the-lich-king, which is kind of cool, but I don’t know if it will mess with SEO.
Thanks! I’m using keesiemeijer’s method and it’s working for displaying the list and the custom fields.
Is it possible to get the name of a page’s parent if it’s not a certain page? For example, something like this:
if ([parent title or slug] != "games") { [get parent's title or slug] }
The website I have is about games, not movies. I used movies as an example because I figured it would be more generally recognized.
So right now, I have a page called “games”. Every video game listing page is a child of the games page. Some video games have expansions though, so the expansion’s game listing is a child of the video game, which is a grandchild of games. I guess another option would be something like:
if ([grandchild of games [or the games id]) { [get parent's title or slug] }
I’m trying to generate the links to each game and expansion in the list I just made. I can get the links to the child pages (games/[game name]) but I can’t figure out how to get links to the grandchildren (games/[game name]/[game’s expansion]). I think if I can find out a grandchild’s parent’s name, I can input that as the [game name] after str_replacing the spaces for “-“.
When something is in brackets in the if statements it’s because I don’t know what code would be used there to get what is inside the brackets ??
Can anyone even see this or did a moderator mark me as the thing that makes it so no one can see my posts…?
I haven’t got a reply to one of my posts in here for like 5 days and I’ve bumped them up once they get on the 3rd page. Like, I’ll see someone answer 6 posts (so they are all at the top at the same time), and one of my posts will be like the 7th one lol, every time. The things I’m asking could be too complicated I guess. I’m just wondering :O
I guess this would be similar to displaying a list of products with their price and stuff.
Forum: Themes and Templates
In reply to: Passing the title attribute to items in wp_login_formBump
Forum: Themes and Templates
In reply to: Getting the number of children and grandchildrenIs this not possible?
Forum: Themes and Templates
In reply to: Getting the number of children and grandchildrenBumping since it’s on the 4th page ??
Forum: Themes and Templates
In reply to: wp_list_pages inconsistencies!I’ve tried with that stuff inside the loop but it doesn’t change anything. Originally, I was having two loops but then replaced the second loop with what is currently (wp_list_pages) and just left it outside of the loop.
Forum: Themes and Templates
In reply to: Is it possible to display the get_post_meta array in order?I have an update:
Okay. I have two pages that use a key more than once. One page, I added like 12 values for the key and they all came out in the correct order. The other page, however, I add 1 value for 1 key and it becomes [0], like it’s supposed to. But, when I add a second value for the key, the first value for the key moves down to [1] and the 2nd value goes to [0]. Then, I add a 3rd value for the key and it makes the first value go to spot [2], the 2nd value stay at spot [0], and then takes the place of spot [1]. I have NO idea why it is jumbling the array spots… I checked the database and the meta_ids are in the correct order. I’ve tried adding one value for the key then updating the page and adding another so each one gets added each update, but that didn’t work either.
I’m about to look into sorting the values depending on meta_ids… I just don’t get why it works on one page when it doesn’t on the other when they use the same template and the values are for the same key. I actually think I’ll try deleting the page and redoing it.
EDIT: Oddly, after deleting the post completely and remaking and re-adding the values, they display in the correct order.
Forum: Themes and Templates
In reply to: Is it possible to display the get_post_meta array in order?Thanks for those posts but it looks like you need to edit query.php for those. I was hoping for some extra parameter that wasn’t in the codex ??
What about a normal PHP sort function or something? Do you happen to know one that would work? I’m still like a beginner ??
Forum: Themes and Templates
In reply to: Is it possible to display the get_post_meta array in order?Here’s a revised post with better information. It doesn’t let me edit the original post anymore ??
Hey guys. I’m using get_post_meta to get an array of all values from a certain set of custom fields. Currently, I guess by default, the get_post_meta array returns all the values starting with the most recent submitted value instead of the first value. For example, I enter 3 different values for the same custom field in this order:
[key] Expansion
[value] The Burning Crusade[key] Expansion
[value] Wrath of the Lich King[key] Expansion
[value] CataclysmBut the array returns them in reverse, so Cataclysm gets displayed first, followed by Wrath of the Lich King; which is opposite of what I need. I wouldn’t mind entering all the custom field info in reverse order (so it would reverse the reverse and come out correct) but I wouldn’t be able to add any more values that I didn’t add the first time. Like, if an expansion came out in 5 months and I wanted to go add that to the custom fields, I would have to re-enter all of them to be able to get them in the correct order.
If there’s no way to display custom fields in the order they are entered, does anyone else have an idea of how I could achieve the same result?