GithubHelp home page GithubHelp logo

Comments (3)

Tetrakern avatar Tetrakern commented on May 13, 2024

Thank you for using Fictioneer, I hope you can make use of it.

Regarding your request, this is not an improvement but an erratic feature. Which is perfectly fine, of course. Display your content how you like. But I cannot bloat the theme further with features barely anyone needs, there are too many of those already. And someone will always come with another, where would this end?

Anyway, you are in luck, because not only can this be achieved (obviously) but also with relative ease. Well, you do need a child theme for some custom code. If you check "Enabled advanced meta fields" under Fictioneer > General > Compatibility, you will be able to use the "Short Title" field in the chapter meta box. This is not actually used by the theme, it is meant for child theme customizations and pretty much the opposite of what you need. But a field is a field.

image

Put this into your child theme's functions.php:

function child_modify_chapter_header( $identity, $args ) {
  // Setup
  $password_class = empty( $args['chapter_password'] ) ? '' : ' _password';
  $other_title = get_post_meta( $args['chapter_id'], 'fictioneer_chapter_short_title', true );
  $icon_classes = fictioneer_get_icon_field( 'fictioneer_chapter_icon', $args['chapter_id'] );
  $icon = '';
  $meta = $identity['meta'];

  // Abort if second title is not set
  if ( empty( $other_title ) ) {
    return $identity;
  }

  // Prepend icon (if any)
  if ( ! empty( $icon_classes ) ) {
    $icon = '<i class="' . $icon_classes . '"></i> '; // Mind the space afterwards
  }

  // Temporary remove meta row
  unset( $identity['meta'] );

  // Rebuild HTML
  $identity['title'] = '<h1 class="chapter__title' . $password_class . '">' . $icon . $args['chapter_title'] . '</h1>';
  $identity['other_title'] = '<h2 class="chapter-second-title">' . $other_title . '</h2>';
  $identity['meta'] = $meta;

  // Continue filter
  return $identity;
}
add_filter( 'fictioneer_filter_chapter_identity', 'child_modify_chapter_header', 10, 2 );
image

You may need to add some custom style targeting the "chapter-second-title" CSS class. The chapter header is not set up for a second title. Why would it? I also prepended the chapter icon, in case you want that.

Modifying the title on the story page (or elsewhere) is a bit more tricky, at least until the next update 5.12.0 which will add a context parameter to the fictioneer_filter_safe_title filter. The update is still a bit off, but not much. Alternatively, you could check whether the current template is the "single-fcn_story.php" and the $post_id belongs to the type "fcn_chapter", but that is not guaranteed to only hit the chapter list under certain circumstances. You should wait for the update (this code will throw an error until then).

function child_modify_chapter_list_title( $title, $post_id, $context ) {
  // Only for chapter lists (story pages and shortcode)
  if ( ! in_array( $context, ['story-chapter-list', 'shortcode-chapter-list'] ) ) {
    return $title;
  }

  // Setup
  $other_title = get_post_meta( $post_id, 'fictioneer_chapter_short_title', true );

  // Abort if second title is not set
  if ( empty( $other_title ) ) {
    return $title;
  }

  // Append to title
  $title = $title . ' — ' . $other_title;

  // Continue filter
  return $title;
}
add_filter( 'fictioneer_filter_safe_title', 'child_modify_chapter_list_title', 10, 3 );
image

Little extra advice: Be careful with adding meta fields, especially if you did not disable post revisions. Each field adds to your post_meta database table, and each revision adds a duplicate of that. So if you have a meta field for 1000 chapters, and each has at least three revisions (you updated it just two times), that means you now got +3000 rows in that database table. Now imagine using even more meta fields. Eventually, this will slow down your site.

Fictioneer has been built with that in mind and only saves what's actually needed. But there's a limit to what I can do. Anyway, I recommend turning off post revisions if you did not already.

from fictioneer.

Tetrakern avatar Tetrakern commented on May 13, 2024

With 5.12.0 released, this should now be good to go.

from fictioneer.

Tetrakern avatar Tetrakern commented on May 13, 2024

Seeing how there's no response coming, I'm closing this now.

from fictioneer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.