1

Topic: echo the content of an ID

I'm setting up an RSS feed for a website, but I'm bumping into a little problem here.
For the description I only want to show a particular part of the page that is inside the body-content element.

The code looks like this now:
<description><?php if ($article->hasContent('body')) { echo $article->content('body'); } ?></description>

In this situation it grabs everything inside the "Body" element.
What I want now, is that is grabs only the content inside the "body" element that has the id #summary.
How would I be able to achieve this?

Thumbs up

2

Re: echo the content of an ID

Its much easier to add the desired content to a pagetab and then check for it.
Here the pagetab is named "myspecialcontent":

<?php
if ($this->hasContent('myspecialcontent')) {
    echo $this->content('myspecialcontent');
}
?>

If that isn't a solution for your usercase then you probally need to look into using DOMDocument or do some other kind of content parsing.

3

Re: echo the content of an ID

In a way it is indeed easier.
But this also requires to double update the content and some content is dynamic.

I'll look into using DOMDocument, thanks for your reply!

Thumbs up

4

Re: echo the content of an ID

petersmit wrote:

What I want now, is that is grabs only the content inside the "body" element that has the id #summary.
How would I be able to achieve this?

If that content comes at the beginning of your "body", then you can use the "Single page-part technique" described in the linked tutorial.

In other words, if your page looks like this:

<h2>Title Here</h2>

<div id="summary">
  <p>This is a summary.</p>
</div>

<p>Rest of content follows....</p>

Then just stick "<!--more-->" in after the closing of your #summary DIV:

<h2>Title Here</h2>

<div id="summary">
  <p>This is a summary.</p>
</div><!--more-->

<p>Rest of content follows....</p>

Then use the code in the tutorial to restrict output. Works well for the RSS feed -- I've used it that way for years.

Using Wolf CMS professionally and for profit? Please consider supporting Wolf financially. Thanks!

5

Re: echo the content of an ID

Another possible PHP/Wolf solution: test for the Layout, and show only the #summary DIV if  the RSS layout is "true".

Maybe?

Using Wolf CMS professionally and for profit? Please consider supporting Wolf financially. Thanks!

6

Re: echo the content of an ID

David wrote:
petersmit wrote:

What I want now, is that is grabs only the content inside the "body" element that has the id #summary.
How would I be able to achieve this?

If that content comes at the beginning of your "body", then you can use the "Single page-part technique" described in the linked tutorial.

In other words, if your page looks like this:

<h2>Title Here</h2>

<div id="summary">
  <p>This is a summary.</p>
</div>

<p>Rest of content follows....</p>

Then just stick "<!--more-->" in after the closing of your #summary DIV:

<h2>Title Here</h2>

<div id="summary">
  <p>This is a summary.</p>
</div><!--more-->

<p>Rest of content follows....</p>

Then use the code in the tutorial to restrict output. Works well for the RSS feed -- I've used it that way for years.

This is what I was looking for! Thanks man!

Thumbs up

7

Re: echo the content of an ID

double update the content and some content is dynamic.ท่องเที่ยวอเมริกา ประเทศมหาอำนาจาIf that isn't a solution for your usercase then you probally need to look into using DOMDocument or do some other kind of content parsing. If that content comes at the beginning of your "body", คาเฟ่สำหรับคนรักน้องหมาthen you can use the "Single page-part technique" described in the linked tutorial.

Thumbs up