• Hello,

    I am trying to get a list of bookmarks categorized with the title of the page’s parent page.

    I have been using the follwing code and everything has been working well so far:

    <?php
    wp_list_bookmarks('&order=DESC&orderby=id&title_li=&categorize=0&category_name='.$parent_title = get_the_title($post->post_parent).'&before=&after=<br />');
    ?>
    </div>

    Recently I have added a new Parent page with an apostrophe in the title and the function will not work.

    Is there a way to ignore or sanitize the apostrophe? Or perhaps an alternate code that gets the bookmark by the category slug rather than the title?

    Thank you

Viewing 10 replies - 16 through 25 (of 25 total)
  • Thread Starter kyledejour

    (@kyledejour)

    Sorry, I’m not sure what you mean.

    I am using this code to call the parent title of the parent page of the child page which I am trying to display the bookmarks

    <?php
    wp_list_bookmarks('&order=DESC&orderby=id&title_li=&categorize=0&category_name='.$parent_title = get_the_title($post->post_parent).'&before=&after=<br />');
    ?>

    How are you assigning a string to the variable $parent_title in the code of your file? Have you checked the contents of this variable.

    Thread Starter kyledejour

    (@kyledejour)

    I’m not sure how to answer that but this is the full code:

    <?php
    /*
    Template Name: Press
    */
    ?>
    
    <?php get_header(); ?>
    
    <div id="container">
    <?php include (TEMPLATEPATH . '/artists_sidebar.php'); ?>
    <div id="main">
    
    <div id="artistnametitle">
    <?php
    $parent_title = get_the_title($post->post_parent);
    echo $parent_title;
    ?>
    <br><br>
    </div>
    
    <a href="https://jessicasilvermangallery.com/<?php
    global $post;
    if($post->post_parent) { $post_data = get_post($post->post_parent);
    echo $post_data->post_name; }
    ?>/selected-works">Selected Works</a> &nbsp;&nbsp;&nbsp; <a href="https://jessicasilvermangallery.com/<?php
    global $post;
    if($post->post_parent) { $post_data = get_post($post->post_parent);
    echo $post_data->post_name; }
    ?>/exhibitions">Exhibitions</a> &nbsp;&nbsp;&nbsp; <a href="https://jessicasilvermangallery.com/<?php
    global $post;
    if($post->post_parent) { $post_data = get_post($post->post_parent);
    echo $post_data->post_name; }
    ?>/CV">CV</a> &nbsp;&nbsp;&nbsp; <a href="https://jessicasilvermangallery.com/<?php
    global $post;
    if($post->post_parent) { $post_data = get_post($post->post_parent);
    echo $post_data->post_name; }
    ?>/press"><u>Press</u></a>
    
    <br><br>
    
    <div id="bookmarks">
    
    <?php
    wp_list_bookmarks('&order=DESC&orderby=id&title_li=&categorize=0&category_name='.$parent_title = get_the_title($post->post_parent).'&before=&after=<br />');
    ?>
    </div>
    
    </div>
    </div>
    
    <?php get_footer(); ?>

    $parent_title = get_the_title($post->post_parent); will not work predictably as you do not have it inside the Loop, You can only use $post->post_parent inside the Loop.

    Thread Starter kyledejour

    (@kyledejour)

    Thank you.

    I tried the following but It does not work for this or for any other instances without the apostrophe that were working before:

    <?php
    wp_list_bookmarks('&order=DESC&orderby=id&title_li=&categorize=0&category_name='.$post->post_parent.'&before=&after=<br />');
    ?>

    I’m not even sure if that code makes sense. Any suggestions?

    Do you understand the Loop?

    Thread Starter kyledejour

    (@kyledejour)

    Somewhat – I managed to build this somewhat complicated site, but it involved a lot of trial and error.

    Thread Starter kyledejour

    (@kyledejour)

    can you offer a suggestion on how to integrate the code you gave me into the code I have now?

    Well, you have no Loop in your template. You need to add a Loop if you want to use $post->post_parent.

    Thread Starter kyledejour

    (@kyledejour)

    Thanks

    Tried this – still not working am I doing it right?

    <?php
    /*
    Template Name: Press
    */
    ?>
    
    <?php get_header(); ?>
    
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <div id="container">
    <?php include (TEMPLATEPATH . '/artists_sidebar.php'); ?>
    <div id="main">
    
    <div id="artistnametitle">
    <?php
    $parent_title = get_the_title($post->post_parent);
    echo $parent_title;
    ?>
    <br><br>
    </div>
    
    <a href="https://jessicasilvermangallery.com/<?php
    global $post;
    if($post->post_parent) { $post_data = get_post($post->post_parent);
    echo $post_data->post_name; }
    ?>/selected-works">Selected Works</a> &nbsp;&nbsp;&nbsp; <a href="https://jessicasilvermangallery.com/<?php
    global $post;
    if($post->post_parent) { $post_data = get_post($post->post_parent);
    echo $post_data->post_name; }
    ?>/exhibitions">Exhibitions</a> &nbsp;&nbsp;&nbsp; <a href="https://jessicasilvermangallery.com/<?php
    global $post;
    if($post->post_parent) { $post_data = get_post($post->post_parent);
    echo $post_data->post_name; }
    ?>/CV">CV</a> &nbsp;&nbsp;&nbsp; <a href="https://jessicasilvermangallery.com/<?php
    global $post;
    if($post->post_parent) { $post_data = get_post($post->post_parent);
    echo $post_data->post_name; }
    ?>/press"><u>Press</u></a>
    
    <br><br>
    
    <div id="bookmarks">
    
    <?php
    wp_list_bookmarks('&order=DESC&orderby=id&title_li=&categorize=0&category_name='.$post->post_parent.'&before=&after=<br />');
    ?>
    </div>
    
    </div>
    </div>
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
    
    <?php get_footer(); ?>
Viewing 10 replies - 16 through 25 (of 25 total)
  • The topic ‘get_bookmarks by parent title is being interupted by an Apostrophe in the title’ is closed to new replies.